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