简体   繁体   English

Casperjs:我如何打印http请求和响应?

[英]Casperjs: How can I print http requests and responses?

For debugging purporses I need to see the whole request: headers and data. 为了调试purporses,我需要查看整个请求:标头和数据。 How can I achieve this? 我怎样才能做到这一点?

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): Casper(实际上是PhantomJS)提供两个回调,一个是在请求资源时 (你可以看到发送的头文件),一个是收到响应时(所以你可以看到服务器回复的头文件):

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);
};

(Using utils module is optional, it just gives nice human-readable formatting. Thanks to thelogix and AlanChavez for the suggestion in the comments.) (使用utils模块是可选的,它只是提供了很好的人类可读格式。感谢thelogix和AlanChavez在评论中的建议。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM