来自gulp的API发布请求不成功

以下请求不成功。 我得到一个回应,但不是一个成功的回应。 我怎样才能解决这个问题? 我已经得到邮递员的请求,但不是一口气。

var proj = { "APIKey": "hidden", "APIPwd": "hidden", "Name": "Sample1", "ReplaceNames": true, "MoveStrings": true, "EncodeStrings": true, "items": [ { "FileName": "test0.js", "FileCode": "function hello(x,y){var z=11;return x+y+z;}" }, { "FileName": "test1.js", "FileCode": "var strs=['aaaa','bbbb','cccc','dddd','eeee','abcdefghijklmnopqrstuvwxyz0123456789']" } ] }; var options = { hostname: 'https://service.javascriptobfuscator.com/HttpApi.ashx', method: 'POST', headers: { 'Content-Type': 'text/json' } }; var req = http.request(options, function(res) { console.log('Status: ' + res.statusCode); console.log('Headers: ' + JSON.stringify(res.headers)); res.setEncoding('utf8'); res.on('data', function (body) { console.log('Body: ' + body); }); }); req.on('error', function(e) { console.log('problem with request: ' + e.message); }); // write data to request body req.write(JSON.stringify(proj)); req.end(); 

这是我得到的回应的开始:

 problem with request: getaddrinfo ENOTFOUND https://service.javascriptobfuscator.com/HttpApi.ashx https://service.javascriptobfuscator.com/HttpApi.ashx:80 IncomingMessage { _readableState: ReadableState { objectMode: false, highWaterMark: 16384, buffer: [], length: 0, pipes: null, pipesCount: 0, flowing: true, ended: true, endEmitted: true, reading: false, sync: true, needReadable: false, emittedReadable: false, readableListening: false, defaultEncoding: 'utf8', ranOut: false, awaitDrain: 0, 

遵循这些文件的http.request ,你的select应该是

 var options = { hostname: 'service.javascriptobfuscator.com', path: '/HttpApi.ashx', method: 'POST', headers: { 'Content-Type': 'text/json' } }; 

您还必须使用https而不是http来保护请求,并通过req.end()结束请求

 var https = require('https'); ... var req = https.request(options, function(res) { // }); req.end();