PHP POST XML data via CURL

WBOY
Release: 2016-08-10 09:07:20
Original
2111 people have browsed it

PHP post xml data to remote address through 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 data packet
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 XML data

CCadd2 BJA0Postal StandardCompany NameNamemobile phoneprovincecityregiondetailed address< /detailAddress>Company nameNameMobile phoneProvince< ;/province>cityregiondetailed address< ;orderLine>CTEST001< ;itemId>Test item one550CTEST002 Test item two5501213333< ;key2>12121313212

I keep getting errors after submitting
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.

There is no error in querying XML message data information. Please help me solve it. Is it because the CURL method is written incorrectly or is there another problem?

Reply content:

PHP post xml data to remote address through 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 data packet
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 XML data

CCadd2 BJA0Postal StandardCompany NameNamemobile phoneprovincecityregiondetailed address< /detailAddress>Company nameNameMobile phoneProvince< ;/province>cityregiondetailed address< ;orderLine>CTEST001< ;itemId>Test item one550CTEST002 Test item two5501213333< ;key2>12121313212

I keep getting errors after submitting
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.

There is no error in querying XML message data information. Please help me solve it. Is it because the CURL method is written incorrectly or is there another problem?

<code>$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;</code>
Copy after login

Sometimes the remote server error returns something like a 500 error. At this time, the returned data is not xml. It is recommended that you print it.

Thank you for the invitation. Got an error after submitting? It is recommended that you make a breakpoint output after submitting to see if there are any error messages. The specific reasons can only be found through bits and pieces of output

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!