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. php - 第三方支付平臺在很短時間內多次異步通知,訂單多次確認收款2. html5 - h5寫的app用的webview,用手機瀏覽器打開不顯示?3. css3 - css before 中文亂碼?4. Mysql && Redis 并發問題5. javascript - node服務端渲染的困惑6. javascript - 百度echarts series數據更新問題7. javascript - webpack --hot 熱重載無效的問題8. mysql新建字段時 timestamp NOT NULL DEFAULT ’0000-00-00 00:00:00’ 報錯9. mysql scripts提示 /usr/bin/perl: bad interpreter10. mysql - 一個表和多個表是多對多的關系,該怎么設計
