0

I am interacting with the battle.net API and I need to get the response body when I hit a 404 page. The problem is I get an error.

I know the page has a body as in the documentation there is an example that has the body (screenshot below). I have also put in a screenshot of my php error. Any help would be appreciated.

Battle.net Docs

here is my code:

$responseCode = get_http_response_code($api); //Checks page exists

if($responseCode == 200) { //Page exists
    $api = "battle.net/apirequest.......";
    $json = file_get_contents($api);
    $schema = json_decode($json, true);

    $completeQuests = $schema['quests'];
} else if ($responseCode == 404) {
     ...Trying to find out why here.....
}

Thanks, James McNee

EDIT: Also when I go directly to the URL I get the JSON response so I really dont know where this error is coming from.

James McNee
  • 302
  • 2
  • 14

1 Answers1

2

file_get_content would not allow you to get the content on failure conditions. To get the content you would have to use a lower level library; something like say curl.

Amit
  • 1,836
  • 15
  • 24
  • I did look into it and you were 100% right, I used CURL to access the page and got the info I needed, thanks for your help! – James McNee Jul 08 '15 at 20:55