PHP使用cURL调用WebService的问题
大家讲道理
大家讲道理 2017-04-10 16:06:58
[PHP讨论组]

我想用PHP的cURL来访问WeatherWS
官网给出的请求示例:

POST /WebServices/WeatherWS.asmx/getWeather HTTP/1.1
Host: www.webxml.com.cn
Content-Type: application/x-www-form-urlencoded
Content-Length: length

theCityCode=string&theUserID=string

我写的代码:

$data = 'theCityCode=广州&theUserID=""';

$curlObj = curl_init();
curl_setopt($curlObj,CURLOPT_URL,'http://www.webxml.com.cn/WebServices/WeatherWS.asmx/getWeather');
curl_setopt($curlObj,CURLOPT_HEADER,0);
curl_setopt($curlObj,CURLOPT_RETURNTRANSFER,1);
curl_setopt($curlObj,CURLOPT_POST,1);
curl_setopt($curlObj,CURLOPT_POSTFIELDS,$data);

curl_setopt($curlObj,CURLOPT_HTTPHEADER,array("application/x-www-form-urlencoded;charset=utf-8","Content-length:".strlen($data)));
$rtn = curl_exec($curlObj);

if(!curl_errno($curlObj)){
    echo $rtn;
}else{
    echo 'Curl error:'.curl_error($curlObj);
}
curl_close($curlObj);

说是免费用户的话theUserID留空,可是执行的结构就是

发现错误:用户验证失败。http://www.webxml.com.cn/

如果不加入theUserID又会提示:

缺少参数: theUserID。

求解??

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

全部回复(0)
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号