简体   繁体   中英

Php file_get_contents Special Characters

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

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? :/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM