0

I'm trying to figure out a way to make a request to a REST api using some PHP client.

Authorization: Token token="CREDENTIALS" 

I can successfully curl it by using

$ curl -H 'Authorization: Token token="CREDENTIALS" https://uriexample.com 

But I can't figure out a way to set this header in any PHP client I tried (Guzzle and Httpful).

Would anyone know how can I do this with ANY PHP client? I just don't wanna code this client from scratch :(

4
  • built in curl library is all you need Commented Mar 28, 2017 at 21:11
  • @nogad if you can illustrate this with an example that can be a good answer Commented Mar 28, 2017 at 21:13
  • stackoverflow.com/a/30600026/2160958 Commented Mar 28, 2017 at 21:17
  • stackoverflow.com/questions/12331224/… Commented Mar 28, 2017 at 21:18

1 Answer 1

1

The Guzzle docs have loads of examples if you dig into them a little. http://docs.guzzlephp.org/en/latest/quickstart.html#making-a-request http://docs.guzzlephp.org/en/latest/request-options.html#headers

<?php // Create HTTP client with headers for all requests $client = new GuzzleHttp\Client([ 'base_uri' => 'https://uriexample.com', 'headers' => [ 'Authorization' => 'Token token="CREDENTIALS"', ], ]); // Dispatch GET request $client->request('GET', '/'); // OR // Create HTTP client $client = new GuzzleHttp\Client([ 'base_uri' => 'https://uriexample.com', ]); // Dispatch GET request with specific headers $client->request('GET', '/', [ 'headers' => [ 'Authorization' => 'Token token="CREDENTIALS"', ], ]); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.