Casperjs:我如何打印http请求和响应? [英] Casperjs: How can I print http requests and responses?

查看:152
本文介绍了Casperjs:我如何打印http请求和响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于调试purporses,我需要查看整个请求:标头和数据。我怎样才能实现这个目标?

For debugging purporses I need to see the whole request: headers and data. How can I achieve this?

推荐答案

Casper(好吧,实际上是PhantomJS)提供两个回调,一个当请求资源时(您可以看到正在发送的标题),以及收到回复(这样您就可以看到服务器回复的标题):

Casper (well, actually PhantomJS) supplies two callbacks, one when the resource is requested (where you can see headers being sent), and one when response is received (so you can see the headers the server replied with):

var utils = require('utils');

var casper = require('casper').create();
casper.options.onResourceRequested = function(C, requestData, request) {
    utils.dump(requestData.headers);
};
casper.options.onResourceReceived = function(C, response) {
    utils.dump(response.headers);
};

(使用 utils 模块是可选的,它只需提供良好的人类可读格式。感谢thelogix和AlanChavez在评论中提出的建议。)

(Using utils module is optional, it just gives nice human-readable formatting. Thanks to thelogix and AlanChavez for the suggestion in the comments.)

这篇关于Casperjs:我如何打印http请求和响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆