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 - js输入框限定字数问题2. 个人主页博客统计中的“进入博客”不能点击3. Browser-sync安装失败问题4. css3 - 微信前端页面遇到的transition过渡动画的bug5. php - 微信开发验证服务器有效性6. python如何设置一个随着系统时间变化的动态变量?7. javascript - Ajax返回json格式之后的数据解析后取出来的数据为undefined?8. javascript - jquery选择的dom元素如何更新?9. 网页爬虫 - 关于Python的编码与解码问题10. javascript - Webapp 关闭后重新打开无需登录如何操作?

网公网安备