file_get_contents和simplexml_load_file为空

时间:2016-12-14 15:46:40

标签: php wordpress

我想从这个网址读取xml:

  

https://username:password@wetter.ws.siag.it/Weather_V1.svc/web/getLastProvBulletin?lang=de

但即使我尝试使用simplexml_load_file($ url),我也会收到此错误:

  

解析器错误:文档为空

当我想用file_get_contents($ url)测试时,我得到一个空字符串

  

“”

这个网站是否有可能阻止脚本?如果是,为什么它适用于wordpressplugin WP All import

我也尝试过curl:

private function curl($url) {
        $headers[]  = "User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13";
        $headers[]  = "Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
        $headers[]  = "Accept-Language:en-us,en;q=0.5";
        $headers[]  = "Accept-Encoding:gzip,deflate";
        $headers[]  = "Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.7";
        $headers[]  = "Keep-Alive:115";
        $headers[]  = "Connection:keep-alive";
        $headers[]  = "Cache-Control:max-age=0";


        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($curl, CURLOPT_ENCODING, "gzip");
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
        $data = curl_exec($curl);
        curl_close($curl);
        return $data;
    }

......同样的问题

0 个答案:

没有答案