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. ddos - apache日志很多其它網址,什么情況?2. 怎么在phpstudy中用phpexcel上傳數據到MYSQL?3. javascript - 百度搜索網站,如何讓搜索結果顯示一張圖片加上一段描述,如圖;求教4. vue.js - centos 使用vue-cli. 執行npm run dev 報錯5. php由5.3升級到5.6后,登錄網站,返回的是php代碼,不是登錄界面,各位大神有知道的嗎?6. 發現了多個名稱為[spring_web]的片段。相對順序不合法7. android - 使用vue.js進行原生開發如何進行Class綁定8. docker綁定了nginx端口 外部訪問不到9. 求救一下,用新版的phpstudy,數據庫過段時間會消失是什么情況?10. html5和Flash對抗是什么情況?
