2017-02-13 143 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