artdarek / oauth-4-laravel

OAuth Service Provider for Laravel 4
685 stars 217 forks source link

Get the response headers #152

Open dskanth opened 9 years ago

dskanth commented 9 years ago

Hi, i would like to know how to view the response headers for a request. For example, i make a request like below:

<?php $serviceFactory = new \OAuth\ServiceFactory(); $tw = OAuth::consumer( 'Twitter' );

$endpoint = '/users/xxx'; $result = json_decode($tw->request( $endpoint, 'GET', '', array() ), true); ?>

Now sometimes i get the result as blank (esp. for POST requests), but the response would still be containing some headers. How can i read those header values? Can someone please help me?

dskanth commented 9 years ago

Well, i identified the request method for the Oauth call, and it contains some code like below:

$response = file_get_contents($endpoint->getAbsoluteUri(), false, $context);

So immediately after that line, i added the below line, to fetch the response headers: $res_headers = $http_response_header;