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 - sublime快鍵鍵問題2. javascript - immutable配合react提升性能?3. vue.js - Vue 如何像Angular.js watch 一樣監聽數據變化4. 配置Apache時,添加對PHP的支持時語法錯誤5. css - 寫頁面遇到個布局問題,求大佬們幫解答,在線等,急!~6. javascript - nodejs關于進程間發送句柄的一點疑問7. javascript - 移動端上不能實現拖拽布局嗎?8. phpstudy8.1支持win11系統嗎?9. 實現bing搜索工具urlAPI提交10. Apache 已經把網站根目錄的改為allow from all了,但是服務器還是不能訪問?

網公網安備