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

时间:2017-05-13 21:25:24

标签: node.js express curl node-libcurl

我是nodejs的新手,所以这可能是操作员错误,但我试图向PayPay的测试网址发出POST请求。我尝试在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

我得到以下结果(我知道使用了安全令牌,但它是卷曲调用的标志):

* 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。我很好奇为什么。如果有一种方法我应该更好地调试,请告诉我。

提前致谢!

1 个答案:

答案 0 :(得分:1)

看来至少URL中的域名有拼写错误,应该是paypal.com而不是payapl.com(这是一个骗局/垃圾网站)。