我查看了API但是没有找到。
在client.request()
或client.request("POST", ...)
中,我应该在哪里/如何放置POST请求的数据?
var rq = client.request('POST', 'http://example.org/', {'Content-Length': '1024'});
var body = getMe1024BytesOfData();
rq.write(body);
rq.end();
这段代码只是为了让概念更清晰。我没有进行任何测试。
你也可以使用Requestify,这是我为nodeJS编写的非常酷炫且非常简单的HTTP客户端,它还支持缓存。
只需执行以下操作即可执行POST请求:
var requestify = require('requestify');
requestify.post('http://example.com', {
hello: 'world'
})
.then(function(response) {
// Get the response body (JSON parsed or jQuery object for XMLs)
response.getBody();
});