3

i have unirest code running in laravel 4.2: (doesn't work)

<?php
    $headers = array('Authorization', 'Bearer TOKENASDKASKDN231DAS2');
    $body    = array();
    $respons = Unirest\Request::get("https://api.request", $headers, $body);
?>
// and this
<?php
  Unirest\Request::auth('TOKENASDKASKDN231DAS2', '');
  $header  = array();
  $body    = array();
  $respons = Unirest\Request::get("https://api.request", $headers, $body);
?>

I tried running this in getpostman

URL: GET - https://api.request

HEADER: Authorization : Bearer TOKENASDKASKDN231DAS2

It actually works. Don't why not in unirest.


I already have a working code with using the Auth Basic:

Authorization: Basic c2tfdGVzdF9uNTA0OWFhNjA1M2M5YTAyMTdiZWE3ODA3MGZiZjUwMTo=

in php:

Unirest\Request::auth('c2tfdGVzdF9uNTA0OWFhNjA1M2M5YTAyMTdiZWE3ODA3MGZiZjUwMTo=', '');

  • 2
    How does it not work? What behavior are you expecting and what behavior are you getting? What error are you getting? – arychj Jun 29 '15 at 14:39

1 Answers1

1

This one is simple.

This is correct, as you said: Unirest\Request::auth('TOKEN HERE', '');

This is not $headers = array('Authorization', 'Bearer TOKENASDKASKDN231DAS2');

Because $headers is getting an array,

it should be array('Authorization' => 'Bearer TOKENHERE');

DO NOT COMPARE HEADER and AUTH

  • That was so stupid of me, it now works.. thanks for tracing that for me. –  Jun 30 '15 at 02:35