日期:2014-05-20 浏览次数:20672 次
<?php function postUrl($url, $postvar) { $ch = curl_init(); $headers = array( "POST ".$url." HTTP/1.0", "Content-type: text/xml; charset=\"gb2312\"", "Accept: text/xml", "Content-length: ".strlen($postvar) ); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_POSTFIELDS, $postvar); $res = curl_exec ($ch); curl_close ($ch); return $res; } $baiduXML = "<?xml version=\"1.0\" encoding=\"gb2312\"?> <methodCall> <methodName>extende</methodName> <params> <param><value><string>name</string></value></param> <param><value><string>我是测试</string></value></param> </methodCall>"; $res = postUrl('http://www.text.com', $baiduXML); ?>