Javascript casperjs响应标头内容长度0
使用Casperjs,我从远程服务器下载了一些apk,但得到了一个空的apk(0字节) 我在回复标题中得到了这个Javascript casperjs响应标头内容长度0,javascript,node.js,nginx,phantomjs,casperjs,Javascript,Node.js,Nginx,Phantomjs,Casperjs,使用Casperjs,我从远程服务器下载了一些apk,但得到了一个空的apk(0字节) 我在回复标题中得到了这个 Server: nginx/1.10.2 Date: Mon, 15 May 2017 06:49:10 GMT Content-Length: 0 Connection: keep-alive X-Robots-Tag: noindex Location:http://website.com/download/someapp.apk Expires: Thu, 01 Jan 197
Server: nginx/1.10.2
Date: Mon, 15 May 2017 06:49:10 GMT
Content-Length: 0
Connection: keep-alive
X-Robots-Tag: noindex
Location:http://website.com/download/someapp.apk
Expires: Thu, 01 Jan 1970 00:00:01 GMT
Cache-Control: no-cache, max-age=0, no-cache, no-store, must-
revalidate, proxy-revalidate, no-transform
Pragma: no-cache
如果URL是正确的,并且您的代码是有效的,那么它应该可以工作。为了帮助您,下面是一个下载当前目录中图像的最简单的工作示例脚本:
var casper = require('casper').create();
casper.start('https://duckduckgo.com', function() {
var url = 'https://duckduckgo.com/assets/logo_homepage.normal.v107.svg';
this.download(url, 'duckduckgo-logo.svg');
});
casper.run(function() {
this.echo('Done.').exit();
});
如果仍然不起作用,可能是安全问题。在这种情况下,请尝试使用casperjs--web security=no download.js运行脚本,或者像这样配置您的Casper实例:
var casper = require('casper').create({
pageSettings: {
webSecurityEnabled: false
}
});
或
casper.page.settings.webSecurityEnabled = false;
casper.page.settings.webSecurityEnabled = false;