-
-
Save artjomb/f3332f2df42114eade13 to your computer and use it in GitHub Desktop.
This example shows that request headers can be set for the download function.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var casper = require('casper').create({ | |
pageSettings: { | |
userAgent: "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36" | |
}, | |
viewportSize: { | |
width: 1280, | |
height: 720 | |
} | |
}); | |
casper.on("remote.message", function(msg){ | |
this.echo("remote.msg: " + msg); | |
}); | |
casper.on("resource.error", function(resourceError){ | |
this.echo("res.err: " + JSON.stringify(resourceError)); | |
}); | |
casper.on("resource.requested", function(resource){ | |
this.echo("res.req: " + JSON.stringify(resource)); | |
}); | |
var url = "http://example.com/"; | |
casper.start().thenOpen(url).then(function() { | |
this.echo("\ndownload begins: default"); | |
this.download(url, "test82_example_default.html", "POST", "content"); | |
this.echo("download ends: default\n"); | |
// headers for the next request | |
this.page.customHeaders = { | |
"Accept-Language": "fr" | |
}; | |
}).thenOpen(url).then(function() { | |
this.echo("\ndownload begins: fr"); | |
this.download(url, "test82_example_fr.html", "POST", "content"); | |
this.echo("download ends: fr\n"); | |
}).run(function(){ | |
this.echo("done").exit(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
E:\shared\temp\casper>casperjs test82_lang_header.js | |
res.req: {"headers":[{"name":"User-Agent","value":"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36"},{"name":"Accept","value":"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"}],"id":1,"method":"GET","time":"2015-03-28T12:58:03.940Z","url":"http://example.com/"} | |
download begins: default | |
res.req: {"headers":[{"name":"Origin","value":"http://example.com"},{"name":"User-Agent","value":"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36"},{"name":"Content-Type","value":"application/x-www-form-urlencoded"},{"name":"Referer","value":"http://example.com/"},{"name":"Accept","value":"*/*"},{"name":"Content-Length","value":"7"}],"id":2,"method":"POST","time":"2015-03-28T12:58:07.023Z","url":"http://example.com/"} | |
download ends: default | |
res.req: {"headers":[{"name":"User-Agent","value":"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36"},{"name":"Accept","value":"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"},{"name":"Accept-Language","value":"fr"}],"id":3,"method":"GET","time":"2015-03-28T12:58:07.522Z","url":"http://example.com/"} | |
download begins: fr | |
res.req: {"headers":[{"name":"Origin","value":"http://example.com"},{"name":"User-Agent","value":"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36"},{"name":"Content-Type","value":"application/x-www-form-urlencoded"},{"name":"Referer","value":"http://example.com/"},{"name":"Accept","value":"*/*"},{"name":"Content-Length","value":"7"},{"name":"Accept-Language","value":"fr"}],"id":4,"method":"POST","time":"2015-03-28T12:58:07.937Z","url":"http://example.com/"} | |
download ends: fr | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment