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. javascript - 数组的过滤和渲染2. ubuntu - 远程连接MySQL,Can’t connect to mysql server on x.x.x.x(10038)3. 高并发写入和更新mysql4. java - String s=new String()与String s = ""的区别5. ddos - apache日志很多其它网址,什么情况?6. MySQL 水平拆分之后,自动增长的ID有什么好的解决办法?7. java - springMVC配置的controller无法返回jsp文件8. javascript - 修改表单多选项时和后台同事配合的问题。9. javascript - 这里为啥会报错?10. html - 微信浏览器h5<video>标签问题
