phpor 发表于 2012-10-25 23:40:13

curl

1 get方式
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 6);
$result = curl_exec($ch);
curl_close($ch);
2 post方式
$url = http://www.sina.com;
$params = array('id'=>11,'aa'=>22,'cc'=>33);
$data = http_build_query($params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if('' != $data){
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
}
curl_setopt($ch, CURLOPT_TIMEOUT, 6);
$result = curl_exec($ch);
var_dump(curl_error($ch));
curl_close($ch);
return $result;
页: [1]
查看完整版本: curl