PHP uses cURL to call WebService

Source: Internet
Author: User
I want to use PHP cURL to access the WeatherWS official website. Example of the request: {code ...} code I wrote: {code ...} if it is a free user, theUserID is left blank, but the execution structure is {code ...} if theUserID is not added, the message {code...} is displayed ...} solution ?? I want to use PHP cURL to access WeatherWS
Request example provided on the official website:

POST /WebServices/WeatherWS.asmx/getWeather HTTP/1.1Host: www.webxml.com.cnContent-Type: application/x-www-form-urlencodedContent-Length: lengththeCityCode=string&theUserID=string

Code I wrote:

$ Data = 'thecitycode = Guangzhou & theUserID = "" '; $ curlObj = curl_init (); curl_setopt ($ curlObj, CURLOPT_URL, 'HTTP: // response '); curl_setopt ($ curlObj, CURLOPT_HEADER, 0); curl_setopt ($ curlObj, expires, 1); curl_setopt ($ curlObj, CURLOPT_POST, 1); curl_setopt ($ curlObj, expires, $ data); curl_setopt ($ curlObj, CURLOPT_HTTPHEADER, array ("application/x-www-form-u Rlencoded; 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 );

If it is a free user, theUserID is left blank, but the execution structure is

Error detected: user verification failed. Http://www.webxml.com.cn/

If theUserID is not added, the following message is displayed:

The parameter theUserID is missing.

Solution ??

Reply content:

I want to use PHP cURL to access WeatherWS
Request example provided on the official website:

POST /WebServices/WeatherWS.asmx/getWeather HTTP/1.1Host: www.webxml.com.cnContent-Type: application/x-www-form-urlencodedContent-Length: lengththeCityCode=string&theUserID=string

Code I wrote:

$ Data = 'thecitycode = Guangzhou & theUserID = "" '; $ curlObj = curl_init (); curl_setopt ($ curlObj, CURLOPT_URL, 'HTTP: // response '); curl_setopt ($ curlObj, CURLOPT_HEADER, 0); curl_setopt ($ curlObj, expires, 1); curl_setopt ($ curlObj, CURLOPT_POST, 1); curl_setopt ($ curlObj, expires, $ data); curl_setopt ($ curlObj, CURLOPT_HTTPHEADER, array ("application/x-www-form-u Rlencoded; 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 );

If it is a free user, theUserID is left blank, but the execution structure is

Error detected: user verification failed. Http://www.webxml.com.cn/

If theUserID is not added, the following message is displayed:

The parameter theUserID is missing.

Solution ??

Let's take a look at it by yourself. [how can we handle timeout errors?] I really don't know how to say it. It's difficult to read documents.

A large number of simple interfaces are not needed on the Internet.
:


  

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.