Casperjs: How can I print http requests and responses?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-18 12:28:19

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/20924928/casperjs-how-can-i-print-http-requests-and-responses

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!