Bing Ads API v8 背景:使用我的 node.js 脚本,我使用 SubmitGenerateReport 操作创建一个 Campaign PerformanceReportRequest,它返回一个 ID,然后我使用该 ID 调用 PollGenerateReport,它返回一个长 URL,例如:
https://download.api.bingads.microsoft.com/ReportDownloadAdCenterAPIDownload.aspx?q=M3poINDSV[删除了大约 200 个字符]05GUMsXBg%3d
使用浏览器或 wget 获取该 URL 会立即返回我需要的文件。
如果我使用浏览器,我还会得到一个友好的文件名,例如“CampaignPerformanceReport_08_29_2013_11_06_54.zip”......使用 wget 我指定 -O 并分配一个文件名。
理想情况下,我想将 zip 文件流式传输到 adm-zip 并即时解压缩,或类似的东西。
但是,我什至无法使用节点 https 或节点请求从 URL 获取 response.statusCode 属性。
我已经搜索并看到了关于节点存在一些已知 ECONNRESET 问题的讨论,但据我所知,它们似乎不适用于我的情况。
我目前的想法是:
关于 .zip 文件响应的长 URL 的某些内容没有被节点接收 - 我试图检测重定向,但就像我提到的那样,我什至没有得到 statusCode
也许我需要为 Bing Ads API 指定一个标题才能满意?
这是一些带有相关错误的代码:
使用节点 HTTPS:
https.get(file_url, function(res) {
console.log("Got response: " + res.statusCode);
console.log("headers.location: " + res.headers.location);
}).on('error', function(e) {
console.log("Got error: " + e.message);
});
大约 35 秒后,返回错误:
Got error: read ECONNRESET
并且没有 .on 错误,更详细地说:
events.js:72
throw er; // Unhandled 'error' event
^
Error: read ECONNRESET
at errnoException (net.js:901:11)
at TCP.onread (net.js:556:19)
使用节点请求:
request(file_url, function (error, response, body) {
if (!response.statusCode == 200) {
console.log(response.statusCode)
}
});
大约 35 秒后,返回错误:
TypeError: Cannot read property 'statusCode' of undefined
at Request._callback (C:\Program Files\nodejs\testzipstream.js:35:18)
at self.callback (C:\Program Files\nodejs\node_modules\request\index.js:148:
22)
at Request.EventEmitter.emit (events.js:95:17)
at ClientRequest.self.clientErrorHandler (C:\Program Files\nodejs\node_modul
es\request\index.js:257:10)
at ClientRequest.EventEmitter.emit (events.js:95:17)
at CleartextStream.socketErrorListener (http.js:1528:9)
at CleartextStream.EventEmitter.emit (events.js:95:17)
at Socket.onerror (tls.js:1424:17)
at Socket.EventEmitter.emit (events.js:117:20)
at net.js:441:14
我错过了什么和/或我还应该调查什么?谢谢!