카테고리:

최대 1 분 소요

소스 코드

$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;

태그: body, curl, DATA, php, php-curl, POST, x-www-form-urlencoded

업데이트: