本篇文章给大家带来的内容是关于php如何使用curl调用webservice来获取天气信息(代码),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
相关代码如下:
<?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来获取天气信息(代码)的详细内容。