Home > Backend Development > PHP Tutorial > How does php use cURL to call WebService to obtain weather information (code)

How does php use cURL to call WebService to obtain weather information (code)

不言
Release: 2023-04-03 20:48:01
Original
2468 people have browsed it

The content of this article is about how PHP uses cURL to call WebService to obtain weather information (code). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

The relevant codes are as follows:

<?php
$data = &#39;theCityName=杭州&#39;;
$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, &#39;Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.62 Safari/537.36&#39;);
$result = curl_exec($curl);
if (!curl_errno($curl)) {
echo $result;
} else {
echo &#39;Curl error:&#39; . curl_error($curl);
}
curl_close($curl);
Copy after login

Related recommendations:

How to use TP5.1 template loop tags (code)

php implementation to generate mixed verification code and image verification code and test (code)

The above is the detailed content of How does php use cURL to call WebService to obtain weather information (code). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template