简体   繁体   中英

Casperjs: How can I print http requests and responses?

For debugging purporses I need to see the whole request: headers and data. 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):

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.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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