2016-12-01 62 views
1

嘗試通過代理髮出POST請求,從而在請求中獲取類似未轉義字符的錯誤。但是沒有代理就可以正常工作。在Node Js中執行發佈請求時獲取「請求路徑包含未轉義字符錯誤」

var request = require('request'); 
request.post({ 
      url: "https://sezion.com/api?accountID=58340ff7c05c1c8dac59e895&accountSecret=XXXXXXXXXXXXXXXXXXXXX=", 
      proxy: "http://proxy.example.com:8989", 
      headers: { 
       "Content-Type": "application/json" 
      }, 
      body: '{"jsonrpc":"2.0","id":"zdoLXrB5IkwQzwV2wBoj","method":"barrister-idl","params":[]}', 
      json:true 
}, function(error, response, body){ 
console.log(error); 
console.log(JSON.stringify(response)); 
    console.log(body); 
}); 

雖然運行此代碼,讓這樣的錯誤,

_http_client.js:53 
    throw new TypeError('Request path contains unescaped characters'); 
    ^

TypeError: Request path contains unescaped characters 
    at new ClientRequest (_http_client.js:53:11) 
    at TunnelingAgent.exports.request (http.js:31:10) 
    at TunnelingAgent.createSocket (D:\Seizon\node_modules\request\tunnel.js:117:25) 
    at TunnelingAgent.createSecureSocket [as createSocket] (D:\Seizon\node_modules\request\tunnel.js:189:41) 
    at TunnelingAgent.addRequest (D:\Seizon\node_modules\request\tunnel.js:81:8) 
    at new ClientRequest (_http_client.js:158:16) 
    at Object.exports.request (http.js:31:10) 
    at Object.exports.request (https.js:199:15) 
    at Request.start (D:\Seizon\node_modules\request\main.js:428:30) 
    at Request.write (D:\Seizon\node_modules\request\main.js:812:28) 
+0

我也有沙塵暴發展這個問題。我能否得到有問題的真實路徑? –

回答

0
var request = require('request'); 
var qs = require('querystring'); 

var url = "https://sezion.com/api?" + 
    qs.stringify({ 
     accountID: '58340ff7c05c1c8dac59e895', 
     accountSecret: 'XXXXXXXXXXXXXXXXXx=' 
    }); 
request.post({ 
    url: url, 
    headers: { 
     "Content-Type": "application/json" 
    }, 
    body: { "jsonrpc": "2.0", "id": "zdoLXrB5IkwQzwV2wBoj", "method": "barrister-idl", "params": [] }, 
    json: true 
}, function (error, response, body) { 
    console.log(error); 
    console.log(JSON.stringify(response)); 
    console.log(body); 
}); 
+0

Thnks,但代碼工作很好,沒有代理...即使這不是worrking –

+0

@siddiqrehman再次嘗試,測試工作,與您的真實accountSecret,無論如何是最好的做法串化/逃脫你querystring – Simon

相關問題