How PHP sends XML in post form

Source: Internet
Author: User
Tags copy curl header reference

This article mainly introduced the PHP to send the XML in the Post form the method, including curl and fsockopen two kinds of methods, has the good reference value, needs the friend to be possible to refer to under

The example in this article describes the way PHP sends XML in post form. Share to everyone for your reference. The specific methods are as follows:

Method one, using curl:

Copy CodeThe 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 Dimension Tutorial Network method Two, using Fsockopen:

Copy CodeThe code is as follows: $fp = Fsockopen ($server _ip, 80);
Fputs ($fp, "POST $path http/1.0\r\n");
Fputs ($FP, "Host: $server \ r \ n");
Fputs ($fp, "content-type:text/xml\r\n");
Fputs ($FP, "content-length: $contentLength \ r \ n");
Fputs ($fp, "connection:close\r\n");
Fputs ($fp, "\ r \ n"); All headers Sent
Fputs ($fp, $xml _data);
$result = ';
while (!feof ($fp)) {
$result. = Fgets ($fp, 128);
}
return $result;

I hope this article will help you with your PHP program design.




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.