phantomjs 自定义、修改http请求头

作者: admin 日期: 2016-06-29 20:39:18 人气: - 评论: 0

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 = {};};


相关内容

发表评论
更多 网友评论0 条评论)
暂无评论

Copyright © 2012-2014 我的代码板 Inc. 保留所有权利。

页面耗时0.0233秒, 内存占用1.83 MB, 访问数据库13次

闽ICP备15009223号-1