php에서는 curl을 이용해서 http request를 간단하게 구현할 수 있다!
다음은 curl로 post 요청을 날리는 샘플 소스이다.
꼭 필요한 부분만 추린 소스라서
curl 이해에 큰 도움이 될 것이다!
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://www.test.com/test.php"); // 호출할 주소
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$post = array('username' => 'testuser', 'password' => '1234567'); // post로 요청할 데이터
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
$server_output = curl_exec($ch); // http request 수행
curl_close($ch);
echo $server_output; // response 출력
다음은 curl로 post 요청을 날리는 샘플 소스이다.
꼭 필요한 부분만 추린 소스라서
curl 이해에 큰 도움이 될 것이다!
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://www.test.com/test.php"); // 호출할 주소
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$post = array('username' => 'testuser', 'password' => '1234567'); // post로 요청할 데이터
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
$server_output = curl_exec($ch); // http request 수행
curl_close($ch);
echo $server_output; // response 출력
'IT노트(구) > PHP' 카테고리의 다른 글
php에서 데이터 날짜 포맷 바꾸는 방법 (0) | 2015.12.03 |
---|---|
(php) print_r() 개념 및 사용 예제 (0) | 2015.12.02 |
php에서 특정 문자열 포함 여부 확인하는 방법(strpos 이용) (0) | 2015.12.01 |
php에서 문자열 자르는 방법(구분자 기준) (0) | 2015.12.01 |
PHP syntax error, unexpected '[' in 에러 해결 방법 (0) | 2015.11.17 |