【问题标题】:node-libcurl obtaining wrong IP address on POSTnode-libcurl 在 POST 上获取错误的 IP 地址
【发布时间】:2017-10-12 23:28:01
【问题描述】:

我是 nodejs 的新手,所以这可能是操作员错误,但我正在尝试向 PayPay 的测试 URL 发出 POST 请求。我尝试在 nodejs 中使用 http 请求,但得到了一个奇怪的响应。我能够在命令行上使用 curl 来工作,所以我想我会在 node.js 中使用 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。我很好奇为什么。如果有一种方法我应该更好地调试它,请告诉我。

提前致谢!

【问题讨论】:

  • 我很好奇,为什么要在 node 的内置 https 模块上使用 libcurl 绑定?
  • 是的...这就是我开始的地方。我得到的是以下错误:{ 错误:在 Socket.emit (events.js:188:7) 的 emitOne (events.js:96:13) 的 Socket.socketOnData (_http_client.js:362:20) 解析错误在 readableAddChunk (_stream_readable.js:176:18) 在 TCP.onread (net.js:551:20) 的 Socket.Readable.push (_stream_readable.js:134:10) bytesParsed: 0, code: 'HPE_INVALID_CONSTANT' }
  • 是不是因为域名不对?我假设您的意思是访问 paypal.com 而不是 payapl.com(这是一个诈骗/垃圾邮件网站)?
  • 是的,就是这样!! curl 调用的操作员错误,如预期的那样。我不知道为什么 http 请求失败,因为 URL 看起来是对的,但我会再次验证。你能把它作为答案,所以我可以给你信用吗?我检查了几次 URL,包括从 curl 调用中剪切和粘贴,但错误的 URL 潜入了。谢谢!

标签: node.js express curl node-libcurl


【解决方案1】:

似乎至少 URL 中的域有错字,应该是 paypal.com 而不是 payapl.com(这是一个诈骗/垃圾邮件网站)。

【讨论】:

  • 感谢您的发现。
猜你喜欢
  • 2014-02-23
  • 2011-03-14
  • 2015-02-23
  • 2016-06-21
  • 2020-12-10
  • 2010-11-04
  • 1970-01-01
  • 2014-10-01
  • 1970-01-01
相关资源
最近更新 更多