欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php以post形式發(fā)送xml的方法

 更新時(shí)間:2014年11月04日 15:15:02   投稿:shichen2014  
這篇文章主要介紹了php以post形式發(fā)送xml的方法,包括了curl與fsockopen兩種方法,具有不錯(cuò)的參考價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了php以post形式發(fā)送xml的方法。分享給大家供大家參考。具體方法如下:

方法一,使用curl:

復(fù)制代碼 代碼如下:
$xml_data = <xml>...</xml>";
$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:

復(fù)制代碼 代碼如下:
$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;

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

希望本文所述對(duì)大家的PHP程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論