2013-05-13 86 views
0

我尝试使用下面的脚本作出HTTPS POST SOAP请求Node.js的HTTPS POST请求的IP地址失败

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(); 

ip地址和有效载荷已经改变。我知道请求成功地工作,作为接头,正确要求的F体和请求的URL工作

执行时,我一直运行到这个错误:

{ [Error: getaddrinfo ENOTFOUND] code: 'ENOTFOUND', errno: 'ENOTFOUND', syscall: 'getaddrinfo' } 

有人能看到我在做什么在制作此HTTPS请求时,此脚本中出现错误?我试着搜索这个错误消息,它一直指向论坛主题关于主机的问题。

任何指针将不胜感激。

回答

4

我在这里可以看到两个问题:

第一:你想使用https,而不是http。因此,您应该使用

var https = require('https'); 

并从此使用https而不是http。有关更多信息,请参阅Node HTTPS。 二,在* post_options *中,主机参数应该只有主机,没有模式。所以让主机:132.33.223.33。这就是为什么你会收到“ENOTFOUND”错误。