Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 474
Euphe Avatar asked Jan 04 '14 18:01

Euphe


1 Answers

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

like image 120
Darren Cook Avatar answered Sep 20 '22 03:09

Darren Cook