Search code examples
httprequestdrupal-7

Can't view GET request to remote API in Chrome


I have set up a section on my Drupal 7 site to show press releases that are fetched from a remote service through a REST API. It works fine to fetch and show all press items via a very specific POST request.

But I have no luck when I want to fetch just one specific press item, which according to the API docs shall be done with a GET request.

In order to see what happens I want to view the GET request to the remote URL in Chrome, but I can't figure out how.

This is how I do it: when opening the page where I want to show only one full press item:

On my press item page...

https://examplesite.com/newsroom/pressrelease

... I have a custom block where this code is run:

$item_id = (int)$_GET['item_id'];

// Fetch specific pressRelease from remote API with custom token
$headers =  array('Custom-Token'=>'[custom-token]', 'Accept'=>'text/json', 'Content-Type'=>'text/json');
$url = "https://[remote newsroom url/]$item_id";
dpm($url);

$options=array(
    'method'=>'GET',
    'headers'=>$headers
);
$result=drupal_http_request($url, $options);
dpm($result);
$data =  json_decode($result->data, true);
dpm($data);

With my dpm statements I can see the request on the page, but I would really like to see the actual request and response in Chrome dev tools (under the Network tab). But there is nothing to be found. I have tried using extensions like Live HTTP Headers, with no luck. Only the request to view the local page is shown not the remote one.

How can I see the http request to the remote URL in Chrome or Firefox?

EDITED... the problem might be that the request is done while the page is generated on the server side, before it is loaded on my site?


Solution

  • The code that you are executing, lies on the server and cannot be viewed from network tools of the browser, The browser developer tools will be able to track only those request that are made directly from your browser, in the form of AJAX request etc.

    In order to view the actual request, you need to use a network proxy like Charles or Fiddler on your server which will track all HTTP network traffic from your server.