dongqiuxu2270 2012-01-06 21:03
浏览 23
已采纳

PHP SimpleXML导致Servererror 500

I just want to read out the google weather api xml with that code but it returns a 500. Any ideas why?

<?php
 $url = "http://www.google.com/ig/api?weather=Moskva&hl=en";
 $xml = simplexml_load_string(utf8_encode(file_get_contents($url)));
 echo $xml->weather->current_conditions->temp_c->attributes()->data;
?>
  • 写回答

3条回答 默认 最新

  • douxiuyu2028 2012-01-06 21:08
    关注

    Separate the lines out and introduce a try / catch block as follows :

    try {
      $url = "http://www.google.com/ig/api?weather=Moskva&hl=en";
      $temp1 = file_get_contents($url);
      $temp2 = utf8_encode($temp1);
      $xml = simplexml_load_string($temp2);
      echo $xml->weather->current_conditions->temp_c->attributes()->data;
    } catch (Exception $e) {
       echo 'Caught exception: ',  $e->getMessage(), "
    ";
    }
    

    what happens then ?

    Updated

    Your response was due to the ip address your are coming from .... this was the response :

    http://www.google.com/sorry/?continue=http://www.google.com/ig/api%3Fweather%3DMoskva%26hl%3Den

    typing the response URL into a browser gives this :

    Our systems have detected unusual traffic from your computer network. This page checks to see if it's really you sending the requests, and not a robot. Why did this happen?

    IP address: 90.214.41.66 Time: 2012-01-06T21:35:24Z URL: http://www.google.com/ig/api?weather=Moskva&hl=en

    Enter the URL in a browser and complete the CAPTCHA - should be sorted then

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效