I'm currently working with Drupal 8's Guzzle HTTP Client.

What I need is the request headers, response headers and the response data (raw html).

Response headers and response data is not the problem:

$client = \Drupal::httpClient();
$response = $client->get('https://www.drupal.org');
$responseHeaders = $response->getHeaders(); //Response Headers array
$body = $response->getBody()->getContents(); // Raw HTML

But what's the way to get the request headers?

I can find a way in documentation of GuzzleHttp version 4 (https://guzzle.readthedocs.org/en/guzzle4/http-messages.html) but nothing like this in version 6 (which is being used by Drupal 8).

  • Well, this is Guzzle version 3 and your link points to the response headers. That's what I already have (as you can see in my post :)) But thanks anyway! – Heisnberg Nov 19 '15 at 17:26
  • docs.guzzlephp.org/en/latest/quickstart.html#using-responses From this version 6 doc, I dont see a similar method. Although creating such a method yourself, shouldn't be terribly difficult ... – tenken Nov 19 '15 at 17:28
  • I think you need to inject Middleware to be able to get access to the Request. The docs are pretty bad about describing Middleware and Handlers despite how verbose that page is. Or, if you're just needing to do it during an error, then the RequestException has a getRequest method. – mradcliffe Nov 24 '15 at 16:15
  • I would need the whole request header. As injecting Middleware without a good doc seems to be very time intensive for me I will use curl now. – Heisnberg Nov 25 '15 at 10:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.