Node.js Request Module…sending json in body for api request with put
来源:互联网 发布:淘宝上买什么东西好 编辑:程序博客网 时间:2024/05/16 16:22
http://stackoverflow.com/questions/21359877/node-js-request-module-sending-json-in-body-for-api-request-with-put
用Node.js的Request模块发送post请求,request body为JSON对象,需要设置json: true
var options = { url: 'https://_rest_full_api headers: { 'X-Auth-Token': token }, body: { 'status' : 'pending' }, json: true, method: 'put'};function callback(error, response, body) { if (!error && response.statusCode == 200) { var info = JSON.parse(body); console.log(info); console.log(info); } else { console.log(response.statusCode); console.log(response.body); }}
With the json option set to true, request is automatically parsing the body for you to an object. You are re-parsing the body with this line:
var info = JSON.parse(body)
When you try to parse an object, you get that message:
$ node> var t = {};> JSON.parse(t);SyntaxError: Unexpected token o
0 0
- Node.js Request Module…sending json in body for api request with put
- Node.js request.body undefined
- jQuery posting valid json in request body
- Using HTTP Proxy in Node.js with request package
- Adding timeout support for http request in Node.JS
- Send string in PUT request with libcurl in C++
- How to disable 'withcredentials' in HTTP header with node.js and Request package?
- No mapping found for HTTP request with URI [/service/model/xxx/json] in DispatcherServlet
- IOException in sending Request :: Connection refused: connect
- No mapping found for HTTP request with URI [/operation-platform/js/displaytag.js] in DispatcherServl
- Request API in Dojo
- SSM报错:No mapping found for HTTP request with URI [/smbms/js/echarts.js] in DispatcherServlet with na
- 1231 Sending the Request
- Node.js的request模块
- node.js的request模块
- oracle数据库 java.lang.Exception: Exception in sending Request :: null
- java.lang.Exception: Exception in sending Request :: null
- oracle java.lang.Exception: Exception in sending Request :: null
- 第四周 建立单链表
- UVa 1585 Score【数组处理】
- 文章标题
- 第4周 项目2 - 建设“单链表”算法库
- 第六周项目1单链表应用
- Node.js Request Module…sending json in body for api request with put
- 第6章深入使用Hibernate 6.1Hibernate的关联映射
- 快速排序之JavaScript实现
- 第三周项目3 求并集合集
- 循环双链表应用
- poj 1830 开关问题 【高斯消元 求解自由变元数目】
- 浅谈Linux下Makefile编写
- 第六周 项目1 -- 建立顺序栈算法库
- 第4周 项目1 - 建立单链表