簡體   English   中英

IP地址上的Node.js HTTPS POST請求失敗

[英]Node.js HTTPS POST Request at IP Address fails

我正在嘗試使用以下腳本發出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();

IP地址和有效負載已更改。 我知道請求成功完成,因為標頭,請求正文和請求url在F中正常工作

執行后,我一直遇到這個錯誤:

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

有人在發出此HTTPS請求時可以看到我在此腳本中做錯了什么嗎? 我嘗試搜索此錯誤消息,它始終指向有關主機問題的論壇主題。

任何指針將不勝感激。

我在這里可以看到2個問題:

首先:您正在嘗試使用https,而不是http。 因此,您應該使用

var https = require( 'https' );

然后,使用https代替http。 有關更多信息,請參見Node HTTPS 其次,在* post_options *中, host參數應僅是主機,而不是模式。 因此,讓主機:132.33.223.33 這就是為什么您會收到“ ENOTFOUND”錯誤的原因。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM