https://www.php.net/manual/en/function.curl-init.php
https://www.php.net/manual/en/function.curl-setopt.php
/**
* @param $url 값을 던질 url
* @param int $is_post post 통신이면 1, get 이면0
* @param array $data 전달할 값
* @param null $custom_header header를 같이 전송할경우
* @return mixed
*
* 사용법
* $params = array( 'P_TID' => '값', 'P_MID' => '값' );
* $strArrResult = request_curl('값을 던질 url', 1, $params);
*/
function request_curl($url, $is_post=0, $data=array(), $custom_header=null) {
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL,$url);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_SSLVERSION,1);
curl_setopt ($ch, CURLOPT_POST, $is_post);
if($is_post) {
curl_setopt ($ch, CURLOPT_POSTFIELDS, $data);
}
curl_setopt ($ch, CURLOPT_TIMEOUT, 300);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
//curl_setopt ($ch, CURLOPT_HEADER, true);
if($custom_header) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $custom_header);
}
$result[0] = curl_exec ($ch);
$result[1] = curl_errno($ch);
$result[2] = curl_error($ch);
$result[3] = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close ($ch);
return $result;
}
'기타 > PHP' 카테고리의 다른 글
'' // "" // 따옴표처리 (0) | 2020.03.31 |
---|---|
fcm (0) | 2019.09.10 |
implode,explode (0) | 2019.06.20 |
php.ini 업로드관련설정값 (0) | 2019.05.03 |
MSSQL_FETCH ROW, ASSOC, ARRAY (0) | 2019.04.15 |