2017-02-13 165 views
0

我已经提出了这个POST方法,我正在调用一个API。不知何故,这是行不通的,我真的不知道为什么。Node.js错误:Http post响应返回ECONNREFUSED

我不断收到301 ECONNREFUSED。我也使用follow-redirects(在GET方法解决了类似的问题)

这是代码:

var http = require('follow-redirects').http; 
var options = { 
      url: 'api.quickpay.net', 
      path: '/payments', 
      method: 'POST', 
      headers: { 
       'Accept-Version' : 'v10', 
       'Authorization' : 'Basic KEY' 
      }, 
      body: { 'currency' : 'dkk', 
        'order_id' : '9999'} 

     }; 

     var quick_req = http.request(options, function(response, error) { 

      if (!error && response.statusCode == 200) { 
       console.log(response.statusCode) 
      } 
     }); 

回答

0

他们的API文档说

Any and all communication is encrypted using a 4096 Bit SHA256 RSA certificate issued by Comodo using the protocols TLS 1.0, 1.1 & 1.2.

所以我认为你需要使用https代替http

+0

这也是我在想的东西,但错误仍然是一样的。 – Englund0110

+0

问题已解决?如果没有:调用API的要求是什么?我需要一个quickpay.net注册吗?我怎样才能得到一个授权密钥来自己尝试? – Marc