PHP中CURL实现GET和POST请求
2021-03-12 13:31
标签:tran custom cells dex use comm tab space ber POST方式实现(推荐) GET方式实现直线导轨滑台 PHP中CURL实现GET和POST请求 标签:tran custom cells dex use comm tab space ber 原文地址:https://www.cnblogs.com/furuihua/p/12826487.html
function
postData(
$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);
curl_setopt(
$ch
, CURLOPT_USERAGENT,
‘Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)‘
);
curl_setopt(
$ch
, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt(
$ch
, CURLOPT_AUTOREFERER, 1);
curl_setopt(
$ch
, CURLOPT_POSTFIELDS,
$data
);
curl_setopt(
$ch
, CURLOPT_RETURNTRANSFER, true);
$tmpInfo
= curl_exec(
$ch
);
if
(curl_errno(
$ch
)) {
return
curl_error(
$ch
);
}
curl_close(
$ch
);
return
$tmpInfo
;
}
function
getData(
$url
){
$ch
= curl_init();
curl_setopt(
$ch
, CURLOPT_URL,
$url
);
curl_setopt(
$ch
, CURLOPT_HEADER,0);
curl_setopt(
$ch
, CURLOPT_RETURNTRANSFER,1);
//禁止调用时就输出获取到的数据
curl_setopt(
$ch
, CURLOPT_FOLLOWLOCATION,1);
curl_setopt(
$ch
, CURLOPT_SSL_VERIFYPEER,false);
curl_setopt(
$ch
, CURLOPT_SSL_VERIFYHOST,false);
$result
= curl_exec(
$ch
);
curl_close(
$ch
);
return
$result
;
}
文章标题:PHP中CURL实现GET和POST请求
文章链接:http://soscw.com/index.php/essay/63704.html