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.