node.js - 如何獲取post請求返回response的值?
問題描述
getUser: function (sessionId) {fetch(’/account_auth_admin_new_test/personal-api.accessLogin’, { method: ’POST’, headers: {’Content-Type’: ’application/json’ }, body: JSON.stringify({sessionId: sessionId,enterpriseCode: 'SUNEEE',clientIp: '127.0.0.1',encryptCode:'1234567899876543',appCode: 'XIANGPU' })}).then(function(res){ console.log(res.json())}).then(function(err){ console.log(’錯誤’,err)}) }
fetch模塊:https://github.com/github/fetch
問題解答
回答1:getUser: function (sessionId) { fetch(’/account_auth_admin_new_test/personal-api.accessLogin’, {method: ’POST’,headers: { ’Content-Type’: ’application/json’},body: JSON.stringify({ sessionId: sessionId, enterpriseCode: 'SUNEEE', clientIp: '127.0.0.1', encryptCode:'1234567899876543', appCode: 'XIANGPU'}) }).then(function(res){return res.json() }).then(function(json) {console.log(’parsed json’, json) }).catch(function(ex) {console.log(’parsing failed’, ex) }).then(function(err){console.log(’錯誤’,err) })}
相關文章:
1. docker鏡像push報錯2. java - SSH框架中寫分頁時service層中不能注入分頁類3. angular.js - angular內容過長展開收起效果4. python3.x - python連oanda的模擬交易api獲取json問題第五問5. nignx - docker內nginx 80端口被占用6. 關于docker下的nginx壓力測試7. debian - docker依賴的aufs-tools源碼哪里可以找到啊?8. html5 - 百度echart官網下載的地圖json數據亂碼9. node.js - 我是一個做前端的,求教如何學習vue,node等js引擎?10. javascript - js代碼獲取驗證碼倒計時問題
