uni*_*der 0 https http http-post node.js
我正在尝试使用以下脚本创建HTTPS POST SOAP请求:
var http = require('http');
function Authenticate() {
// Build the post string from an object
var post_data = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:typ=\"http://company.com/mse/types\"><soapenv:Header/><soapenv:Body><typ:Login><typ:Credential userName=\"username\" password=\"password\"/></typ:Login></soapenv:Body></soapenv:Envelope>";
// An object of options to indicate where to post to
var post_options = {
port: 443,
host: 'https://132.33.223.33', //MSE12
path: '/aaa/',
method: 'POST',
headers: {
'Content-Type': 'text/xml;charset=UTF-8',
'SOAPAction': '\"Login\"',
'Accept-Encoding': 'gzip,deflate',
'Host':'173.37.206.33',
'Connection':'Keep-Alive',
'User-Agent':'Apache-HttpClient/4.1.1 (java 1.5)'
}
};
// Set up the request
var post_req = http.request(post_options, function(res) {
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('Response: ' + chunk);
});
});
post_req.on('error', function (err) {
//handle error here
console.log(err);
});
// post the data
post_req.write(post_data);
post_req.end();
}
Authenticate();
Run Code Online (Sandbox Code Playgroud)
IPAddress和有效负载已更改.我知道请求成功,因为Headers,请求正文和请求URL在F中正常工作
执行时,我一直遇到这个错误:
{ [Error: getaddrinfo ENOTFOUND] code: 'ENOTFOUND', errno: 'ENOTFOUND', syscall: 'getaddrinfo' }
Run Code Online (Sandbox Code Playgroud)
在发出此HTTPS请求时,任何人都可以在此脚本中看到我做错了吗?我尝试搜索此错误消息,它一直指向论坛主题与主机的问题.
任何指针将不胜感激.
小智 6
我在这里可以看到2个问题:
第一:你正在尝试使用https,而不是http.因此你应该使用
var https = require( 'https' );
Run Code Online (Sandbox Code Playgroud)
从那时起,使用https而不是http.有关详细信息,请参阅节点HTTPS.其次,在*post_options*中,host参数应该只是主机,没有架构.所以让主持人:132.33.223.33.这就是你得到"ENOTFOUND"错误的原因.