用于中文的get和post请求的函数
时间:2005-11-11 来源:blueday
function http_get($url,$header=array("Content-Type: text/xml;charset=utf-8"))
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$ret = curl_exec($ch);
curl_close($ch);
return $ret;
}
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$ret = curl_exec($ch);
curl_close($ch);
return $ret;
}
function http_post($url,$params,$xml_post = true)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_POST, 1);
if($xml_post) curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml"));
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$ret = curl_exec($ch);
curl_close($ch);
return $ret;
}
相关阅读 更多 +