我想使用 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/