Curl queries the current weather by calling WebService

Source: Internet
Author: User

<?PHP/** * Curl queries the current weather in Beijing by calling WebService*/Header("content-type:text/html; Charset=utf-8 ");$data= ' Thecityname= Beijing ';//passed Parameters$curl _obj= Curl_init ();//Initialize a Curl session//Set URL and corresponding optionscurl_setopt ($curl _obj, Curlopt_url, "http://www.webxml.com.cn/WebServices/WeatherWebService.asmx/getWeatherbyCityName");//Set a Curl transfer optioncurl_setopt ($curl _obj, Curlopt_useragent, "user-agent:mozilla/5.0 (Windows NT 5.1; rv:24.0) gecko/20100101 firefox/24.0 ");//A string that contains a "user-agent" header in an HTTP requestcurl_setopt ($curl _obj, Curlopt_header, 0);////Close file header output, invisible, when enabled, the header file information is exported as the data stream. curl_setopt ($curl _obj, Curlopt_returntransfer, 1);//input to the file, rather than direct output to the browser, if successful only return the results, do not automatically output any content. False if failure is returnedcurl_setopt ($curl _obj, Curlopt_post, 1);//a regular POST request is sent when enabledcurl_setopt ($curl _obj, Curlopt_postfields,$data);//data required for postcurl_setopt ($curl _obj, Curlopt_httpheader,Array("application/x-www-form-urlencoded; Charset=utf-8 "," Content-length: ".strlen($data)));$rtn= Curl_exec ($curl _obj);//perform a Curl sessionif(!curl_errno ($curl _obj)){//returns the last error number     $info= Curl_getinfo ($curl _obj);//gets the information for a Curl connection resource handle    Echo' <pre> '; Echo($rtn); Echo' </pre> ';}Else{    Echo' Curl error: '. Curl_error ($curl _obj);//returns a string that secures the most recent error in the current session}curl_close ($curl _obj);//close a Curl session

Output content:

  Beijing 54511 54511.jpg 2016-7-12 23:01:10 23 ℃/32 ℃ July 12 showers or thunderstorms turn cloudy without continuous wind breeze no Thing.gif 1.gif Weather Today: Temperature: 25 ℃, Wind/Wind: North Wind 1, Humidity: 72%, UV intensity: medium.  Air quality: good. UV index: Medium, rub SPF greater than 15, pa+ sunscreen skin care products. Cold index: Less hair, cold odds, avoid long-term in the air-conditioned room. Clothing index: Hot, recommended to wear blouses, shorts and other cool summer clothing. Car Wash Index: Not suitable, rain, rain and mud will stain the car. Sports index: Less suitable, there is precipitation, it is recommended that you indoor leisure sports.  Air Pollution Index: good, meteorological conditions conducive to the spread of air pollutants. 25℃/34℃7 13th Sunny Turn cloudy without continuous wind breeze 0.gif 1.gif 24 ℃/33 ℃ July 14 Cloudy No continuous Wind breeze 1.gif 1.gif Beijing is located in North China Plain Northwest Edge, the city center is located at latitude 39 degrees, east longitude 116 degrees, four weeks by Hebei The province is surrounded by southeast and Tianjin. The city area of more than 16,000 square kilometers, jurisdiction 12 District 6 counties, population more than 11 million. Beijing for warm temperate semi-humid continental monsoon climate, summer hot and rainy, cold winter dry, spring, autumn short, the annual average temperature of 10-12 degrees Celsius. Beijing is one of the world's historical and cultural cities and ancient capitals. As early as 700,000 years ago, the Beijing Zhoukoudian area appeared the primitive crowd tribe "Peking person". The city of Beijing has been built for more than more than 2000 years, originally recorded in the name of the "Thistle." 1045 BC, Beijing became the capital of the kingdom of Thistles, Swallows and other princes; Since the unification of Qin Shihuang in 221, Beijing has been the central and local center of northern China, and since the beginning of the 938, Beijing has also become the Liao Provisional capital, the gold, the yuan, the Ming and Qing capitals. October 1, 1949 formally designated as the capital of the People's Republic. Beijing has a wealth of tourism resources, opening up more than 200 tourist attractions, there are the world's largest palace of the Forbidden City, Temple of Heaven, the Royal Garden of the North Sea, royal gardens, the Summer Palace, as well as Badaling, Mutianyu, Sima Simatai City and the world's largest courtyard Gong Palace and other monuments. There are 7309 items of cultural relics and monuments in the city, including 42 national Cultural Relics Protection Units and 222 municipal Cultural relics Protection Units. Beijing's city tree is the country Huai and the cypress, The Flower of Roses and chrysanthemum. In addition, the Beijing production of ivory sculpture, Jade carving, cloisonne, carpets and other traditional handicrafts renowned the world. 

Curl queries the current weather by calling WebService

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.