私は、httpとhttpsのネイティブパッケージが好きです。レンダリングプロセスで直接リクエストを行うことができます。以下は、エラー処理を伴うサンプル投稿要求です。多分もっと良い解決策があるかもしれません - これは私の扱いです。
// You Key - Value Pairs
var postData = querystring.stringify({
key: "value"
});
// Your Request Options
var options = {
host: "example.com",
port: 443,
path: "/path/to/api/endpoint",
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': Buffer.byteLength(postData)
}
};
// The Request
var request = https.request(options, function(response) {
response.on('data', function(chunk) {
if (chunk) {
var data = chunk.toString('utf8');
// holds your data
}
});
}).on("error", function(e) {
// Some error handling
});
//optionally Timeout Handling
request.on('socket', function(socket) {
socket.setTimeout(5000);
socket.on('timeout', function() {
request.abort();
});
});
request.write(postData);
request.end();