Je commence à apprendre le PHP en jouant avec l'API de wunderground. J'ai l'exemple de code ci-dessous d'eux qui fonctionne localement lors de tests avec xanampp/apache mais quand je le mets sur un serveur web réel en direct sur Internet, il ne semble pas faire l'appel au service Web.Demande de service Web en PHP
code:
<?php
$json_string = file_get_contents("http://api.wunderground.com/api/key/geolookup/conditions/q/IA/Cedar_Rapids.json");
$parsed_json = json_decode($json_string);
$location = $parsed_json->{'location'}->{'city'};
$temp_f = $parsed_json->{'current_observation'}->{'temp_f'};
echo "Current temperature in ${location} is: ${temp_f}\n";
?>
Résultats localement sur ma machine avec xampp:
Current temperature in Cedar Rapids is: 77.4
Résultats sur serveur Web que je paie pour héberger des pages:
Current temperature in is:
rapport d'erreur:
Warning: file_get_contents(): http:// wrapper is disabled in the server configuration by allow_url_fopen=0 in /hermes/bosnaweb01b/b2414/ipg.domainID/testt.php on line 5 Warning: file_get_contents(http://api.wunderground.com/api/key/geolookup/conditions/q/IA/Cedar_Rapids.json): failed to open stream: no suitable wrapper could be found in /hermes/bosnaweb01b/b2414/ipg.domainID/testt.php on line 5 Notice: Trying to get property of non-object in /hermes/bosnaweb01b/b2414/ipg.domainID/testt.php on line 7 Notice: Trying to get property of non-object in /hermes/bosnaweb01b/b2414/ipg.domainID/testt.php on line 7 Notice: Trying to get property of non-object in /hermes/bosnaweb01b/b2414/ipg.domainID/testt.php on line 8 Notice: Trying to get property of non-object in /hermes/bosnaweb01b/b2414/ipg.domainID/testt.php on line 8 Current temperatdure in is:
quoi faire: 'echo" La température actuelle dans ". $ Location." Est: ". $ temp_f. "\ n"; – Pogrindis
Avez-vous activé le rapport d'erreurs complet? La raison la plus probable est que votre fichier json ne peut pas être récupéré (soit parce que 'allow_url_fopen' est désactivé, soit parce qu'il y a d'autres problèmes.) – Wrikken
@Wrikken ne sais pas comment activer le rapport d'erreurs. avoir une certaine expérience avec les services Web, mais pas avec php – user2941841