使用Request模块发布数组/对象

sae*_*eed 2 arrays post object request node.js

我正在尝试使用请求模块发出http post请求

text = 'some data';

request.post('http://example.com/read', {form:{data: text}});
Run Code Online (Sandbox Code Playgroud)

这适用于简单的字符串,但我需要能够发送数组或对象.

当我尝试读取post处理程序中的数组/对象时,data属性为空.

这是怎么回事?非常感谢您的帮助.

JP *_*son 8

试试这个:

var request = require('request');

request({
  method: 'POST',
  uri: 'http://example.com/read',
  body: {'msg': 'secret'},
  json: true
}, function (error, response, body) {
  console.log('code: '+ response.statusCode);
  console.log(body);
})
Run Code Online (Sandbox Code Playgroud)

如果有效,请告诉我.

  • 是的。完美的。反正我从来不想用表格,只是觉得有必要。谢谢 (2认同)