时间:2021-07-01 10:21:17 帮助过:4人阅读
相关代码如下:
<?php $data = 'theCityName=杭州'; $curl = curl_init(); curl_setopt($curl,CURLOPT_URL,"http://www.webxml.com.cn/WebServices/WeatherWebService.asmx/getWeatherbyCityName"); curl_setopt($curl,CURLOPT_HEADER,0); curl_setopt($curl,CURLOPT_RETURNTRANSFER,1); curl_setopt($curl,CURLOPT_POST,1); curl_setopt($curl,CURLOPT_POSTFIELDS,$data); curl_setopt($curl,CURLOPT_HTTPHEADER,array( "application/x-www-form-urlencoded; charset=utf-8", "Content-length: ".strlen($data) )); curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.62 Safari/537.36'); $result = curl_exec($curl); if (!curl_errno($curl)) { echo $result; } else { echo 'Curl error:' . curl_error($curl); } curl_close($curl);
相关推荐:
TP5.1模板循环标签的使用方法(代码)
php实现生成混合验证码与图像验证码并测试(代码)
以上就是php如何使用cURL调用WebService来获取天气信息(代码)的详细内容,更多请关注Gxl网其它相关文章!