Php method of sending XML as post, Phppost form XML
This example describes how PHP sends XML as a post. Share to everyone for your reference. Here's how:
Method One, use curl:
Copy the Code code 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);
Method Two, use Fsockopen:
Copy the Code code 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 is helpful to everyone's PHP programming.
PHP via post to send XML, I PHP new, hope can write detailed points
? What does it mean
PHP how to post XML to a specified server
============================= Supplementary Answer
The following is a well-written class of post XML:
Class Xmlsender {
/**
* Constructor
* Verify that CURL is not available
*/
function Xmlsender ()
{
if (!extension_loaded (' curl ')) {
Trigger_error ("You need CURL loaded to the use of this class", e_user_error);
}
}
/**
* Send XML content using the Curl Library
*/
function Send ($str _xml, $str _url, $str _page, $boo _ssl = False)
{
$str _header = "POST". $str _page. "http/1.0 \ r \ n";
$str _header. = "mime-version:1.0 \ r \ n";
$str _header. = "content-type:application/pti26 \ r \ n";
$str _header. = "Content-length:". strlen ($str _xml). "\ r \ n";
$str _header. = "Content-transfer-encoding:text \ r \ n";
$str _header. = "request-number:1 \ r \ n";
$str _header. = "document-type:response\r\n";
$str _header. = "Interface-version:site 1.0 \ r \ n";
$str _header. = "Connection:close \r\n\r\n";
$str _header. = $str _xml;
$res _curl = Curl_init ();
curl_setopt ($res _curl, Curlopt_url, $str _url);
curl_setopt ($res _curl, Curlopt_returntransfer, 1);
curl_setopt ($res _curl, Curlopt_timeout, 30);
curl_setopt ($res _curl, curlopt_customrequest, $str _header);
curl_setopt ($res _curl, curlopt_followlocation, 1);
...... Remaining full text >>
http://www.bkjia.com/PHPjc/906111.html www.bkjia.com true http://www.bkjia.com/PHPjc/906111.html techarticle PHP sends XML in post form, phppost form XML This article describes the way PHP sends XML as a post. Share to everyone for your reference. The method is as follows: Method One, make ...