3

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

text = 'some data';

request.post('http://example.com/read', {form:{data: text}});

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

当我尝试在后处理程序中读取数组/对象时,数据属性为空。

这是怎么回事?您的帮助将不胜感激。

4

1 回答 1

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);
})

让我知道它是否有效。

于 2012-09-19T18:28:28.313 回答