當前位置:編程學習大全網 - 網站源碼 - php curl http請求 相關問題

php curl http請求 相關問題

1、服務器必須支持 curl

print_r(http(網址));

function http($url,$method='',$data=null){

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_TIMEOUT, 60);

switch ($method) {

case 'POST':

curl_setopt($ch, CURLOPT_POST, TRUE);

if (!empty($data)) {

curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

}

break;

}

curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);

curl_setopt($ch, CURLOPT_HEADER, 0);

$output = curl_exec($ch);

curl_close($ch);

return $output;

}

  • 上一篇:怎麽做壹個抽獎小程序系統
  • 下一篇:釣魚來了輔助輔助槍有什麽作用?
  • copyright 2024編程學習大全網