-
[PHP] cURL 사용해서 post 데이터 넘겨주기프로그래밍/Web(CSS + HTML + JS + PHP ) 2023. 2. 20. 12:37728x90
소스 코드
$clientID = "Client ID"; $clientSecret = "Client SecretKey"; $url = "https://www.example.com"; $body = array("foo" => "test", "bar" => "test"); # type1 $body = "foo=test&bar=test"; # type2 $ch = curl_init(); //curl 초기화 curl_setopt_array($ch, array( CURLOPT_URL => $url, //URL 지정하기 CURLOPT_POST => true, //true시 post 전송 CURLOPT_RETURNTRANSFER => true, //요청 결과를 문자열로 반환 CURLOPT_HTTPHEADER => array(// header data "X-Client-Id" => $clientID, "X-Client-Secret" => $clientSecret, "Content-Type: application/x-www-form-urlencoded" ), CURLOPT_SSL_VERIFYPEER => 0, //원격 서버의 인증서가 유효한지 검사 안함 CURLOPT_POSTFIELDS => $body //POST data )); $response = curl_exec($ch); $status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); return $response;
728x90댓글