※「≈≈≈」は省略を表す
バージョン
$ node -v
v6.2.1
$ cat package.json
{
≈≈≈
"dependencies": {
"request": "~2.72.0",
}
}
POSTでJSONデータを送信する
var request = require('request');
var options = {
uri: "http://example.com/test",
headers: {
"Content-type": "application/json",
},
json: {
"key1": "param1",
"key2": "param2"
}
};
request.post(options, function(error, response, body){});
おまけ:POSTでパラメータを送信する(いわゆるフツーのPOST)(未検証)
var request = require('request');
var options = {
uri: "http://example.com/test",
headers: {
"Content-type": "application/x-www-form-urlencoded",
},
form: {
"key1": "param1",
"key2": "param2"
}
};
request.post(options, function(error, response, body){});