《PHP編程:php以post形式發送xml的方法》要點:
本文介紹了PHP編程:php以post形式發送xml的方法,希望對您有用。如果有疑問,可以聯系我們。
PHP編程本文實例講述了php以post形式發送xml的辦法.分享給大家供大家參考.具體辦法如下:
PHP編程辦法一,使用curl:
代碼如下:
$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);
PHP編程辦法二,使用fsockopen:
代碼如下:
$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;
PHP編程PS:這里再為大家提供幾款關于xml操作的在線工具供大家參考使用:
PHP編程在線XML/JSON互相轉換工具:
PHP編程在線格式化XML/在線壓縮XML:
PHP編程XML在線壓縮/格式化工具:
PHP編程希望本文所述對大家的PHP程序設計有所贊助.
維易PHP培訓學院每天發布《PHP編程:php以post形式發送xml的方法》等實戰技能,PHP、MYSQL、LINUX、APP、JS,CSS全面培養人才。
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/14234.html