7

When I listen to all the HTTP Request with the Chrome API , how can I get the actual data recieved from it?

I mean if the request is made on a php page (XMLHttpRequest), how can I get the content of this page?

.

I am now quering the data with an ajax request. But this isn't a good solution.

The main problem is when the request uses POST method. The data recieved from the ajax query is not the same as the data recived from the HttpRequest.

Paul Fournel
  • 10,807
  • 9
  • 40
  • 68
  • 2
    The `webRequest` API [does not](http://stackoverflow.com/questions/10874417/chrome-webrequest-api-capture-post-data) offer a way to read the response body. Since you've mentioned that you want to intercept AJAX requests, there's a solution though. See [Scrape / eavesdrop AJAX data using JavaScript?](http://stackoverflow.com/a/13768794/938089) – Rob W Jul 04 '13 at 14:42
  • possible duplicate of [Scrape / eavesdrop AJAX data using JavaScript?](http://stackoverflow.com/questions/13765031/scrape-eavesdrop-ajax-data-using-javascript) – Rob W Jul 04 '13 at 14:42
  • Actually it's not the same problem because I would really like to get the result of the XMLHttpRequest. Why doesn't Google let us access to the response body? Is it Security issues? – Paul Fournel Jul 07 '13 at 10:09
  • 2
    There's no other way besdes the one proposed in the duplicate. The webRequest API does not allow inspection and modification of the response body because of performance concerns - Star this issue if you want to get notified of any future updates on this feature: https://code.google.com/p/chromium/issues/detail?id=104058#c19 – Rob W Jul 07 '13 at 10:15

1 Answers1

1

Sorry for that you can't get response body via webRequest, and what I do is try a ajax request to request the url for the second time. It's ugly, I have to request the content using background script, but It does work.

var get=function(url,callback){
var xmlRequest=new XMLHttpRequest();
xmlRequest.open('GET',url,true);
xmlRequest.send();

xmlRequest.onreadystatechange=function(){
 if(xmlRequest.readyState==4){
   callback(xmlRequest.responseText);
  }
 };
};

you can get the response body from xmlRequest.responseText

Arnold
  • 210
  • 1
  • 6
  • 13