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. python - 如何使用jsom.dumps获得完整的json数据?2. javascript - 又是this指向问题3. mysql - 查询字段做了索引为什么不起效,还有查询一个月的时候数据都是全部出来的,如果分拆3次的话就没问题,为什么呢。4. html5和Flash对抗是什么情况?5. javascript - 怎么优化多个ajax请求6. html5 - vue.js中,如何对转义字符进行表达式判断?7. css - 新手做响应式布局, 断点过后右侧出现空白,求帮助,谢谢。8. html5 - ajax post请求后如何渲染到页面上9. golang - gorm无法连接mysql?账号密码都对了10. python - django里GROUP BY 如何写这样的mysql语句?
