PHP cURL不返回XML [英] PHP cURL not returning XML

查看:115
本文介绍了PHP cURL不返回XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用PHP和cURL从www.wowarmory.com获取字符数据。



我到目前为止的代码是:

  ... 
$ browser =Mozilla / 5.0(X11; U; Linux i686; en-US; rv:1.8.1.2 )Gecko / 20070319 Firefox / 2.0.0.3;

$ url =http://www.wowarmory.com/character-sheet.xml?r=Ner'zhul&n=Visar;

$ ch = curl_init();
curl_setopt($ ch,CURLOPT_URL,$ url);
curl_setopt($ ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ ch,CURLOPT_CONNECTTIMEOUT,15);
curl_setopt($ ch,CURLOPT_USERAGENT,$ browser);

$ result = curl_exec($ ch);

var_dump($ result)为false,如果我尝试将$ result解析为XML $ result为空白。



我想获得的是一个字符XML文件。 ( http://www.wowarmory.com/character -sheet.xml?r = Ner%27zhul& n = Visar ),但没有附加XSL。

解决方案

调用:

p>

  echo curl_error($ ch);因为curl_exec返回false,表示错误。

/ p>

I'm trying to get character data from www.wowarmory.com using PHP and cURL.

The code I have so far is:

...        
$browser = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.2) Gecko/20070319 Firefox/2.0.0.3";

$url = "http://www.wowarmory.com/character-sheet.xml?r=Ner'zhul&n=Visar";

$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 15);
curl_setopt ($ch, CURLOPT_USERAGENT, $browser);

$result = curl_exec($ch);

The var_dump($result) is false, and if I try to parse the $result into an XML the $result is blank.

What I'm trying to get is a characters XML file. (http://www.wowarmory.com/character-sheet.xml?r=Ner%27zhul&n=Visar), but without the XSL attached. Then parse this, and extract info from the file, but I just need to get the file first.

解决方案

Call:

echo curl_error($ch);

after the curl_exec to see what the error is since curl_exec is returning false, which indicates an error.

这篇关于PHP cURL不返回XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆