Home >Backend Development >PHP Tutorial >How to send xml in php in post form, phppost form xml_PHP tutorial
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:
Method 2, use fsockopen:
I hope this article will be helpful to everyone’s PHP programming design.
? What does it mean
============================== Supplementary answer
The following is a written post XML class:
class xmlSender {
/**
* Constructor
* Verify whether cURL is available
*/
function xmlSender()
{
if ( !extension_loaded('curl') ) {
trigger_error("You need cURL loaded to use this class", E_USER_ERROR);
}
}
/**
* Use cURL library to send xml content
*/
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);
...The rest of the full text>>