0

im gonna use an api to get player details. Some names are with special characters.

Name Bausí

Url: https/eu.api.battle.net/wow/character/Blackrock/Bausí?fields=statistics&locale=en_GB&apikey=xxx

if i use file_get_contens() there is no response.

Names without special characters works perfectly. I already used rawurlencode() and urlencode(). Both are not working. What can i do? I read something about urlencode() and rawurlencode() is server dependant.

Thanks Chzn

chzn
  • 35
  • 1
  • 7
  • Most probably you need to encode the unicode characters. – S.I. Oct 11 '16 at 13:46
  • Try with answers from this thread: http://stackoverflow.com/questions/2236668/file-get-contents-breaks-up-utf-8-characters – S.I. Oct 11 '16 at 13:47
  • not working i ´ve done $charname = mb_convert_encoding("Bausí", "HTML-ENTITIES", "UTF-8"); and insert it into the url. still not working – chzn Oct 11 '16 at 14:13
  • https://eu.api.battle.net/wow/character/Blackrock/Bausí?fields=statistics&locale=en_GB&apikey=xxx still not getting any content. but the name is right in url. What can be another problem – chzn Oct 11 '16 at 14:16
  • file_get_contents() fail – chzn Oct 11 '16 at 14:31

1 Answers1

0

Well i dont know whats wrong.

                $charname = mb_convert_encoding("Bausí", "HTML-ENTITIES", "UTF-8");
                $realm = "Blackrock";
                $_SESSION["region"] = "eu";
                $opts = array('https' => array('header' => 'Accept-Charset: UTF-8, *;q=0'));
                $context = stream_context_create($opts);

                $char_params = array(
                    'fields' => "statistics",
                    'locale' => "en_GB",
                    'apikey' => "my_api_key"
                );

                $char_url = "https://".$_SESSION['region'].".api.battle.net/wow/character/".str_replace("'","",$realm)."/".$charname."?".http_build_query($char_params);

                if (!$json_char_o = file_get_contents($char_url, false, $context)) {
                      $error = error_get_last();
                      echo "HTTPs request failed. Error was: " . $error['message'];
                }else{
                      echo $json_char_decoded = json_decode($json_char_o);

                }

it throws me an error:

HTTP request failed. Error was: file_get_contents(https://eu.api.battle.net/wow/character/Blackrock/Bausí?fields=statistics&locale=en_GB&apikey=my_api_key): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found

The response should be a json object.

If i open the link manually it works perfectly. What is wrong? :/

chzn
  • 35
  • 1
  • 7