php以post形式發(fā)送xml的方法
本文實例講述了php以post形式發(fā)送xml的方法。分享給大家供大家參考。具體方法如下:
方法一,使用curl:
$url = 'http://www.xxxx.com';
$header[] = "Content-type: text/xml";//定義content-type為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);
方法二,使用fsockopen:
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;
PS:這里再為大家提供幾款關(guān)于xml操作的在線工具供大家參考使用:
在線XML/JSON互相轉(zhuǎn)換工具:
http://tools.jb51.net/code/xmljson
在線格式化XML/在線壓縮XML:
http://tools.jb51.net/code/xmlformat
XML在線壓縮/格式化工具:
http://tools.jb51.net/code/xml_format_compress
希望本文所述對大家的PHP程序設計有所幫助。
相關(guān)文章
PHP實現(xiàn)微信掃碼登錄功能的兩種方式總結(jié)
這篇文章主要為大家介紹了利用PHP實現(xiàn)微信掃碼登錄功能的兩種方式,文中的示例代碼講解詳細,對我們學習有一定借鑒價值,需要的可以參考一下2022-08-08smarty內(nèi)置函數(shù){loteral}、{ldelim}和{rdelim}用法實例
這篇文章主要介紹了smarty內(nèi)置函數(shù){loteral}、{ldelim}和{rdelim}用法,實例分析了{loteral}、{ldelim}和{rdelim}的功能及使用技巧,需要的朋友可以參考下2015-01-01PHP array_flip() 刪除重復數(shù)組元素專用函數(shù)
array_flip() 返回一個反轉(zhuǎn)后的 array,例如 trans 中的鍵名變成了值,而 trans 中的值成了鍵名。2010-05-05