node-libcurl在POST上获取错误的IP地址

我是新来的nodejs,所以这可能是运营商错误,但我试图做一个POST请求PayPay的testingurl。 我尝试在nodejs中使用http请求,但得到了一个奇怪的回应。 我能够让命令行上的curl工作,所以我想我会在节点中使用curl。

当我在bash中运行下面的curl命令时,它工作:

curl -v --data "USER=myLogin&VENDOR=myLogin&PARTNER=PayPal&PWD=QQQQQQQQQ&CREATESECURETOKEN=Y&SECURETOKENID=fb7810e9-252b-4613-a53b-6432148bfd97&TRXTYPE=S&AMT=100.00" https://pilot-payflowpro.paypal.com 

我得到了以下结果(我知道使用了安全令牌,但它是curl调用工作的一个标志):

 * Rebuilt URL to: https://pilot-payflowpro.paypal.com/ * Trying 173.0.82.163... * Connected to pilot-payflowpro.paypal.com (173.0.82.163) port 443 (#0) * found 173 certificates in /etc/ssl/certs/ca-certificates.crt * found 704 certificates in /etc/ssl/certs * ALPN, offering http/1.1 * SSL connection using TLS1.2 / RSA_AES_256_CBC_SHA256 * server certificate verification OK * server certificate status verification SKIPPED * common name: pilot-payflowpro.paypal.com (matched) * server certificate expiration date OK * server certificate activation date OK * certificate public key: RSA * certificate version: #3* subject: C=US,ST=California,L=San Jose,O=PayPal\, Inc.,OU=Payflow Production,CN=pilot-payflowpro.paypal.com * start date: Wed, 08 Feb 2017 00:00:00 GMT * expire date: Thu, 28 Feb 2019 23:59:59 GMT * issuer: C=US,O=Symantec Corporation,OU=Symantec Trust Network,CN=Symantec Class 3 Secure Server CA - G4 * compression: NULL * ALPN, server did not agree to a protocol > POST / HTTP/1.1 > Host: pilot-payflowpro.paypal.com > User-Agent: curl/7.47.0 > Accept: */* > Content-Length: 179 > Content-Type: application/x-www-form-urlencoded > * upload completely sent off: 179 out of 179 bytes < HTTP/1.1 200 OK < Connection: close < Server: VPS-3.033.00 < Date: Sat, 13 May 2017 20:13:38 GMT < Content-type: text/namevalue < Content-length: 121 < * Closing connection 0 RESULT=7&RESPMSG=Field format error: Secure Token Id already beenused&SECURETOKENID=fb7810e9-252b-4613-a53b-6432148bfd97e 

然后,我使用下面的nodejs代码(在通过Express公开的方法中,作为GET):

 var newSId = uuid.v4(); var curl = new Curl(); var url = 'https://pilot-payflowpro.payapl.com/'; var data = { 'USER': 'myLogin', 'VENDOR': 'myLogin', 'PARTNER': 'PayPal', 'PWD': 'QQQQQQQQQQQ', 'CREATESECURETOKEN': 'Y', 'SECURETOKENID': newSId, 'TRXTYPE': 'S', 'AMT': '100.00' }; data = qstr.stringify(data); console.log("Data = " + data); curl.setOpt(Curl.option.URL, url); curl.setOpt(Curl.option.POSTFIELDS, data); curl.setOpt(Curl.option.POST, 1); curl.setOpt(Curl.option.VERBOSE, true); curl.perform(); curl.on('end', function(statusCode, body){ this.close(); }); curl.on('error', curl.close.bind(curl)); 

当我通过浏览器执行GET时,我得到以下信息转储到控制台:

 Data = USER=myLogin&VENDOR=myLogin&PARTNER=PayPal&PWD=QQQQQQQQ&CREATESECURETOKEN=Y&SECURETOKENID=4b8f0763-2d09-4c2a-a57e-f5a4dc5be744&TRXTYPE=S&AMT=100.00 * Trying 209.15.13.134... * connect to 209.15.13.134 port 443 failed: Connection refused * Failed to connect to pilot-payflowpro.payapl.com port 443: Connection refused * Closing connection 0 

由于我无法解释的原因,在node-libcurl调用中,正在使用不同的IP地址。 curl命令行调用使用:173.0.82.163,但node-libcurl使用:209.15.13.134。 我很好奇为什么。 如果有方法我应该更好地debugging,请让我知道。

提前致谢!

看来,至less在url中的域名有一个错字,它应该是paypal.com,而不是payapl.com(这是一个骗局/垃圾邮件网站)。

Interesting Posts