
allow_url_fopen이 비활성화된 상태에서 php에서 http request를 보내는 방법은 두 가지 방법이 있습니다.
1. curl 라이브러리 사용: curl 라이브러리를 사용하여 http request를 보내는 방법입니다. curl 라이브러리는 php의 기본 라이브러리이므로, 별도의 설치가 필요하지 않습니다. 예를 들어, 다음 코드를 사용하여 http request를 보낼 수 있습니다.
#hostingforum.kr
php
$ch = curl_init('http://example.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
2. stream_context_create 사용: stream_context_create 함수를 사용하여 http request를 보내는 방법입니다. stream_context_create 함수는 php의 기본 함수이므로, 별도의 설치가 필요하지 않습니다. 예를 들어, 다음 코드를 사용하여 http request를 보낼 수 있습니다.
#hostingforum.kr
php
$opts = array(
'http' => array(
'method' => 'GET',
'header' => 'Accept-language: enrn',
),
);
$context = stream_context_create($opts);
$response = file_get_contents('http://example.com', false, $context);
두 방법 모두 http request를 보내는 데 사용할 수 있습니다. 그러나 curl 라이브러리를 사용하는 방법이 더 편리하고灵活한 방법입니다.
2025-03-09 10:04