[PHP] POST 방식으로 웹 주소에 값 보내고 결과값 받기 (file_get_contents, curl) > PHP

본문 바로가기

PHP

[PHP] [PHP] POST 방식으로 웹 주소에 값 보내고 결과값 받기 (file_get_contents, curl)

회원사진
하나를하더라도최선을
2022-07-12 08:00 1,190 0

본문



../../apps/IT_HUB/html/202207120753.html


$data = array('title' => $post_title, 'num' => $post_number);


    $post_field_string = http_build_query($fields, '', '&');


    $ch = curl_init();    // curl 초기화

    curl_setopt($ch, CURLOPT_URL, $url);    // url 지정하기

    curl_setopt($ch, CURLOPT_POST, true);    // POST 전송 여부

    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data, '', '&'));    // POST DATA


    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);    // 요청 결과를 문자열로 받음

    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);    // curl이 첫 응답 시간에 대한 timeout : 10초

    curl_setopt($ch, CURLOPT_TIMEOUT, 60);    // curl 전체 실행 시간에 대한 timeout

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);    // 원격 서버의 인증서가 유효한지 검사하지 않음    

    curl_setopt($ch, CURLOPT_HTTPHEADER, array(

'Host: 192.168.0.100',

'User-Agent: curl',

'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',

'Accept-Language: ko-KR,ko;q=0.8,en-US;q=0.5,en;q=0.3',

'Content-Type: application/x-www-form-urlencoded',

'Referer: http://program1472.com/',

'Connection: keep-alive',

'Upgrade-Insecure-Requests: 1'

));

$response = curl_exec($ch);    // 요청 결과

      curl_close ($ch);

//echo $response;


/*

요청 결과를 받지 않아도 된다면, 'CURLOPT_RETURNTRANSFER'를 false로 바꾸고 '$result = curl_exec($ch);'를 'curl_exec($ch);'로 바꾸어도 된다.

CURLOPT_CONNECTTIMEOUT은 처음으로 응답을 받기까지 기다리는 시간(단위: 초)이다.

전체 요청 시간이 CURLOPT_TIMEOUT을 넘기면 전체 작업을 강제로 끝낸다. CURLOPT_TIMEOUT은 file_get_contents 함수에서 넣는 timeout과 같다.

*/

[이 게시물은 하나를하더라도최선을님에 의해 2022-07-12 08:00:20 vb.net에서 이동 됨]

댓글목록0

등록된 댓글이 없습니다.
게시판 전체검색