CURL模拟GET/POST请求,亲测可用
程序员文章站
2022-05-07 15:21:39
...
static function getApi($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 6.0)');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT , 10);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
static function postApi($url,$data){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
if (!empty($data)){
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
推荐阅读
-
Linux下模拟http的get/post请求(curl or wget)详解
-
深入理解curl类,可用于模拟get,post和curl下载
-
Linux下模拟http的get/post请求(curl or wget)详解
-
Java中Https发送POST请求[亲测可用]
-
curl类,可用于模拟get,post和curl下载
-
深入理解curl类,可用于模拟get,post和curl下载
-
深入理解curl类,可用于模拟get,post和curl下载_php技巧
-
深入理解curl类,可用于模拟get,post和curl下载_php技巧
-
curl类,可用于模拟get,post和curl下载_PHP教程
-
深入理解curl类,可用于模拟get,post和curl下载_PHP