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

node-libcurl obtaining wrong IP address on POST

我是 nodejs 的新手,所以这可能是操作错误,但我正在尝试向 PayPay 的测试 URL 发出 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

我得到以下结果(我知道使用了安全令牌,但这表明 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。我很好奇为什么。如果有什么方法我应该更好地调试它,请告诉我。

提前致谢!

看来至少 URL 中的域有错别字,应该是 paypal.com 而不是 payapl.com(这是一个 scammy/spammy 站点)。