node.js - Node.js 中的 eBay API 调用返回 'Input transfer has been terminated because your request timed out'

标签 node.js ebay-api

我想使用 eBay API 获取SessionId。我使用 Node.js 作为后端。在响应中我收到此错误:

Input transfer has been terminated because your request timed out.

要获取sessionId,我正在使用以下方法。

var xml = '<?xml version="1.0" encoding="utf-8"?>'+
'<GetSessionIDRequest xmlns="urn:ebay:apis:eBLBaseComponents">'+
 '<RuName>MyRuname</RuName>'+
'</GetSessionIDRequest>';

var options = {
host: "api.sandbox.ebay.com",
path: '/ws/api.dll',
method: "POST",
body: xml,
headers: {
    'X-EBAY-API-APP-NAME': 'my app id',
    'X-EBAY-API-DEV-NAME': 'my dev id',
    'X-EBAY-API-CERT-NAME': 'my cert id',
    'X-EBAY-API-COMPATIBILITY-LEVEL': '557',
    'X-EBAY-API-CALL-NAME': 'GetSessionID',
    'X-EBAY-API-SITEID':'203',
    'Content-Type' : 'text/xml',
    'Content-Length':xml.length
}
};

var req = https.request(options, function (res) {
  console.log("statusCode: ", res.statusCode);
  console.log("headers: ", res.headers);

   res.on('data', function (d) {
     process.stdout.write(d);

  });

});

req.end();

req.on('error', function (e) {
   console.error('error=======', e);
});

最佳答案

如果您发送空的 POST 正文,则可能会发生错误。如果你看一下nodejs docs您将看到使用 https.request 创建请求对象时没有 body 选项。

在请求中设置body的正确方法是调用req.write调用 req.end

之前的方法
var options = {
    host: "api.sandbox.ebay.com",
    path: '/ws/api.dll',
    method: "POST",
    headers: {
        'X-EBAY-API-APP-NAME': 'my app id',
        'X-EBAY-API-DEV-NAME': 'my dev id',
        'X-EBAY-API-CERT-NAME': 'my cert id',
        'X-EBAY-API-COMPATIBILITY-LEVEL': '557',
        'X-EBAY-API-CALL-NAME': 'GetSessionID',
        'X-EBAY-API-SITEID':'203',
        'Content-Type' : 'text/xml',
        'Content-Length':xml.length
    }
};

var req = https.request(options, function (res) {
    console.log("statusCode: ", res.statusCode);
    console.log("headers: ", res.headers);

    res.on('data', function (d) {
        process.stdout.write(d);
    });
});

req.on('error', function (e) {
    console.error('error=======', e);
});

req.write(xml);

req.end();

关于node.js - Node.js 中的 eBay API 调用返回 'Input transfer has been terminated because your request timed out',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21725961/

相关文章:

javascript - eslint package.json "Failed to parse json"错误

javascript - eBay API 使用 Javascript 按关键字查找商品返回 'Uncaught TypeError'

php - 使用 SoapClient 从 PHP 中的 WSDL 获取元素

javascript - 有没有办法将变量从 client.js 文件发送到您的 node.js 文件?

php - 使用 PHP 将行双重传递到 MySQL 数据库中

java - 错误 ebay [CDATA[ 应用程序内部错误 ]]

c# - 返回结束晚于 10 天的拍卖

mysql - 如何跨多个服务器nodejs和socket.io存储socket.id

node.js - 使用 `__dirname` 引用本地文件的 typescript

node.js - 如何使用 Stripe 防止重复收费?