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 - js 修改表格元素的,可以用DOM操作實現嗎?2. python中def定義的函數加括號和不加括號的區別?3. 用tp5框架寫sql語句4. javascript - 請教移動端從詳情頁返回到列表頁原來位置的問題?5. python - xpath提取網頁路徑沒問題,但是缺失內容?6. javascript - js一個call和apply的問題?7. 跪求解答關于emmetc插件生效的問題8. javascript - js setTimeout在雙重for循環中如何使用?9. 點擊頁面就自動輸入到mysql.求解10. javascript - 關于微信公眾號開發的一個trouble!
