Home > Backend Development > PHP Tutorial > How to send xml in php form_PHP tutorial

How to send xml in php form_PHP tutorial

WBOY
Release: 2016-07-13 10:14:51
Original
947 people have browsed it

How to send xml in PHP form

This article mainly introduces the method of sending XML in PHP in the form of post, including curl and fsockopen. It has good reference value. Friends who need it can refer to it

The example in this article describes the method of sending XML in PHP form. Share it with everyone for your reference. The specific method is as follows:

Method 1, use curl:

Copy code The code is as follows: $xml_data = ...";
$url = 'http://www.xxxx.com';
$header[] = "Content-type: text/xml";//Define content-type as xml
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_data);
$response = curl_exec($ch);
if(curl_errno($ch))
{
print curl_error($ch);
}
curl_close($ch);

Network Tutorial Method 2, use fsockopen:

Copy code The code is as follows: $fp = fsockopen($server_ip, 80);
fputs($fp, "POST $path HTTP/1.0rn");
fputs($fp, "Host: $serverrn");
fputs($fp, "Content-Type: text/xmlrn");
fputs($fp, "Content-Length: $contentLengthrn");
fputs($fp, "Connection: closern");
fputs($fp, "rn"); // all headers sent
fputs($fp, $xml_data);
$result = '';
while (!feof($fp)) {
$result .= fgets($fp, 128);
}
return $result;

I hope this article will be helpful to everyone’s PHP programming design.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/907373.htmlTechArticleHow to send XML in PHP form. This article mainly introduces the method of sending XML in PHP form, including There are two methods of curl and fsockopen, which have good reference prices. Friends who need them can refer to...
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