我尝试在php中使用cURL获取xml文件,url为http://game1-cbt.ma.sdo.com:10001/connect/app/exploration/fairyhistory?cyt=1,但返回的字符串搞砸了。我google了,我尝试了curl_setopt($ c,CURLOPT_ENCODING,'');但它仍然无法正常工作。出现的内容没有变化。这是我的完整计划
$url = "http://game1-cbt.ma.sdo.com:10001/connect/app/exploration/fairyhistory";
$ua="Million/100 (m0; m0xx; 4.2.2) samsung/m0xx/m0:4.2.2/JDQ39/I9300XXUFME3:user/release-keys";
$cookies = "S=85g158t9j3t4hi6kmcf47rbjh1";
$c = curl_init();
curl_setopt($c,CURLOPT_URL,$url);
curl_setopt($c,CURLOPT_HEADER,0);
curl_setopt($c,CURLOPT_RETURNTRANSFER,TRUE);
curl_setopt($c,CURLOPT_USERAGENT,$ua);
curl_setopt($c, CURLOPT_ENCODING, '');
curl_setopt($c,CURLOPT_COOKIE,$cookies);
$r = curl_exec($c);
echo $r;
更新
它适用于UA评论的那一行。谢谢大家!
PS: UA来自我从移动在线游戏中捕获的一个包,我正试图模拟游戏的动作。
答案 0 :(得分:0)
$url = "http://game1-cbt.ma.sdo.com:10001/connect/app/exploration/fairyhistory";
$ua = "Million/100 (m0; m0xx; 4.2.2) samsung/m0xx/m0:4.2.2/JDQ39/I9300XXUFME3:user/release-keys";
$cookies = "S=85g158t9j3t4hi6kmcf47rbjh1";
$c = curl_init();
curl_setopt($c, CURLOPT_URL, $url);
curl_setopt($c, CURLOPT_HEADER, 0);
curl_setopt($c, CURLOPT_RETURNTRANSFER, TRUE);
//curl_setopt($c, CURLOPT_USERAGENT, $ua); - you don't need this
curl_setopt($c, CURLOPT_ENCODING, '');
curl_setopt($c, CURLOPT_COOKIE, $cookies);
$r = curl_exec($c);
echo $r;
答案 1 :(得分:0)
此代码中curl_setopt($c,CURLOPT_USERAGENT,$ua);
出错了删除它,
更好地使用另一个UA
如果已移除curl_setopt($c,CURLOPT_USERAGENT,$ua);
,
请注意,如果您在浏览器中直接回显此内容,请检查来源(查看来源)以符合