您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php以post形式发送xml的方法_php技巧

2024/7/9 8:05:33发布34次查看
本文实例讲述了php以post形式发送xml的方法。分享给大家供大家参考。具体方法如下:
方法一,使用curl:
复制代码 代码如下:
$xml_data = ...;
$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:
复制代码 代码如下:
$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程序设计有所帮助。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product