PHP POST XML Data via Curl

Source: Internet
Author: User
PHP post XML data to remote address via curl
1. CURL Post Method
$ch = Curl_init ();
$timeout = 30;
curl_setopt ($ch, Curlopt_url, $url);
curl_setopt ($ch, Curlopt_post, 1);
curl_setopt ($ch, Curlopt_httpheader, Array ("Content-type:text/xml; Charset=utf-8 "));
curl_setopt ($ch, Curlopt_returntransfer, 0);
curl_setopt ($ch, Curlopt_postfields, $data);//post submitted packets
curl_setopt ($ch, Curlopt_connecttimeout, $timeout);
curl_setopt ($ch, Curlopt_header, 0);
$result = curl_exec ($ch);

Curl_close ($ch);
Header (' Content-type:text/xml; Charset=utf-8 ');

2. The following is the XML data

CC add2 bja 0 Postal label Fast Company name name Mobile phone province City area Detailed address Company Name name mobile phone province City area Detailed address CTEST001 test items 5 CTES T002 test Items two 5 1213333 1212 1313212

After submission has been an error
This page contains the following errors:

Error on line 1 at-column 50:space required after the public Identifier
Below is a rendering of the page up to the first error.

Query XML message data information There is nothing wrong, ask the hero to solve is the curl method of writing wrong or other problems

Reply content:

PHP post XML data to remote address via curl
1. CURL Post method
$ch = Curl_init ();
$timeout = 30;
curl_setopt ($ch, Curlopt_url, $url);
curl_setopt ($ch, Curlopt_post, 1);
curl_setopt ($ch, Curlopt_httpheader, Array ("Content-type:text/xml; Charset=utf-8 "));
curl_setopt ($ch, Curlopt_returntransfer, 0);
curl_setopt ($ch, Curlopt_postfields, $data);//post submitted packets
curl_setopt ($ch, Curlopt_connecttimeout, $timeout);
curl_setopt ($ch, Curlopt_header, 0);
$result = curl_exec ($ch);

Curl_close ($ch);
Header (' Content-type:text/xml; Charset=utf-8 ');

2. The following is the XML data

CC add2 bja 0 Postal label Fast Company name name mobile phone province City Region Detail Address Company name name Mobile Phone Province City Area Detailed address CTEST001 test items 5 CTES T002 test Items two 5 1213333 1212 1313212

After submission has been an error
This page contains the following errors:

Error on line 1 at-column 50:space required after the public Identifier
Below is a rendering of the page up to the first error.

Query XML message data information There is nothing wrong, ask the hero to solve is the curl method of writing wrong or other problems

$ch = curl_init();$timeout = 30; curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type:text/xml; charset=utf-8"));curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0); curl_setopt($ch, CURLOPT_POSTFIELDS, $data);//Post提交的数据包curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);curl_setopt($ch, CURLOPT_HEADER, 0);$result = curl_exec($ch);curl_close($ch);echo $result;

Sometimes the remote server error returned is similar to the 500 error, this time the returned data is not XML, it is recommended that you print a bit.

Thank you for inviting me. Error after submission? It is recommended that you make a breakpoint output after submission to see if there is any error message. Specific reason can only a little bit of output look for

  • 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.