phantomjs是一款可以使用js语言操控并兼容nodejs的无界面webkit引擎,
有的时候需要在加载页面的时候自定义http请求头,查找了下官网的文档发现可以用customHeaders属性来控制发起http请求时的http请求头
Examples
Send two additional headers ‘X-Test’ and ‘DNT’
var webPage = require('webpage');var page = webPage.create();page.customHeaders = {
"X-Test": "foo",
"DNT": "1"};
Do you only want these customHeaders
passed to the initial page.open
request?
Here’s the recommended workaround:
var webPage = require('webpage');var page = webPage.create();page.customHeaders = {
"X-Test": "foo",
"DNT": "1"};page.onInitialized = function() {
page.customHeaders = {};};