반응형
2021.12.30 - [취업/PHP] - [php] curl 통신 유형 post,get,put, delete
기존 코드들이 POST 방식의 Curl이었는데, 해당 방법은 qs 방식
Delete QueryString방식
function cDelQS($param, $url, $token)
{
$query = http_build_query($param);
$domain = $url . "?" . $query;
$header = array(
'Content-Type: application/x-www-form-urlencoded',
'Accept: application/json',
'Authorization: Bearer '. $token
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_URL, $domain);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
PUT QueryString 방식
function cPutQS ($param, $url, $token)
{
$query = http_build_query($param);
$domain = $url . "?" . $query;
$header = array(
'Content-Type: application/x-www-form-urlencoded',
'Accept: application/json',
'Authorization: Bearer '.$token
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_URL, $domain);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
이상 끝.
728x90
'취업 > CodeIgniter' 카테고리의 다른 글
[CI4] CI4 4.2 version 자동라우팅 불가. (0) | 2023.02.15 |
---|---|
[Datatable] 배열 검색 기능. (0) | 2023.02.13 |
[CI4] PHP md5 동일 파일 체크하기. (0) | 2023.01.05 |
[CI4] Jquery sortable 적용하기 (0) | 2022.12.30 |
[CI4] 다날 API PHP 연동작업 후기 (0) | 2022.12.18 |