node.js - 如何獲取post請(qǐng)求返回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(’錯(cuò)誤’,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(’錯(cuò)誤’,err) })}
相關(guān)文章:
1. macos - mac下docker如何設(shè)置代理2. angular.js - ng-grid 和tabset一起用時(shí),grid width默認(rèn)特別小3. apache - 本地搭建wordpress權(quán)限問題4. 熱切期待朱老師的回復(fù),網(wǎng)頁視頻在線播放器插件配置錯(cuò)誤5. docker 下面創(chuàng)建的IMAGE 他們的 ID 一樣?這個(gè)是怎么回事????6. java - Spring Mvc全局異常處理器@ControllerAdvice不起作用?7. Whitelabel錯(cuò)誤頁面發(fā)生意外錯(cuò)誤(類型=未找到,狀態(tài)= 404)/WEB-INF/views/home.jsp8. javascript - web網(wǎng)頁版app返回上一頁按鈕在ios設(shè)備失效怎么辦?安卓上可以,代碼如下,請(qǐng)大神幫助,萬分感謝。9. Android下,rxJava+retrofit 并發(fā)上傳文件和串行上傳文件的效率為什么差不多?10. css3 - transition屬性當(dāng)鼠標(biāo)一開的時(shí)候設(shè)置的時(shí)間不起作用
