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. docker-compose 為何找不到配置文件?2. ddos - apache日志很多其它網址,什么情況?3. 請問一下各位老鳥 我一直在學習獨孤九賤 現在是在tp5 今天發現 這個系列視頻沒有實戰4. android - E/dalvikvm: Could not find class java.nio.file.Path,5. boot2docker無法啟動6. python是怎么實現過濾 #注釋代碼的?7. javascript - 前端開發 本地靜態文件頻繁修改,預覽時的緩存怎么解決?8. mysql數據庫每次查詢是一條線程嗎?9. python - linux怎么在每天的凌晨2點執行一次這個log.py文件10. 使用uuid,并不能利用mysql的索引,有什么解決辦法?
