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. javascript - 使用form進行頁面跳轉,但是很慢,如何加一個Loading?2. javascript - ES6規范下 repeat 函數報錯 Invalid count value3. python 計算兩個時間相差的分鐘數,超過一天時計算不對4. angular.js - angularjs 注入模塊報錯 很怪異... 求解惑5. javascript - JS 里面的 delete object.key 到底刪除了什么?6. angular.js - 輸入郵箱地址之后, 如何使其自動在末尾添加分號?7. mysql - 電商如何存儲營業額數據8. java如何生成token?9. html5 - 為什么使使用vue cli 腳手架,post-css 沒有自動對css3屬性自動添加瀏覽器前綴呢?10. javascript - html5的data屬性怎么指定一個function函數呢?
