2

I'm trying to get Unirest working on my Laravel 4.0 framework.

Right now I'm using REST Countries v1 API and I'm having this issue while trying to get all countries: http://i.gyazo.com/3876755ebdf9b3e71c03a0e801975053.png if I remove the authorization, it returns a normal response saying to authorize but as soon as I authorize and try to get all countries it throws the whole mashape website on my localhost page.

<?php
Unirest::verifyPeer(false);
$response = Unirest::get(
    "https://restcountries-v1.p.mashape.com", // This should return ALL the countries
    array(
        "X-Mashape-Authorization" => "secret-code"
    ),
    null
);
?>
{{ $response->raw_body }} // echo $response->raw_body

But when I try to get by country code, it works like expected

<?php
Unirest::verifyPeer(false);
$response = Unirest::get(
    "https://restcountries-v1.p.mashape.com/alpha/ru", // This should return only russia
    array(
         "X-Mashape-Authorization" => "secret-code"
    ),
    null
);
?>
{{ $response->raw_body }} //echo $response->raw_body

http://i.gyazo.com/72017ce438f91cab8c9b16c50bba12d3.png

Why doesn't the first code example work but rather echo the whole Mashape website??

Kristjan Kirpu
  • 674
  • 1
  • 7
  • 26
  • 2
    I have the same issue when attempting to figure this out. It appears that ``https://restcountries-v1.p.mashape.com/`` responds with headers ``HTTP/1.1 302 Moved Temporarily`` and it redirects to ``https://www.mashape.com/fayder/REST-Countries-v1`` which would explain why it's echoing out the entire page. Maybe you should submit it as an issue. – JaTochNietDan Mar 17 '14 at 18:43

0 Answers0