
stream_context_set_default() 함수는 PHP의 HTTP 요청에 사용되는 stream context의 기본값을 설정하는 함수입니다. 이 함수의 기본값은 NULL입니다. NULL은 stream context를 설정하지 않는다는 의미입니다.
stream_context_set_default() 함수를 사용하여 요청을 보내는 방법은 다음과 같습니다.
#hostingforum.kr
php
$opts = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-Type: application/x-www-form-urlencoded',
'content' => 'key=value',
),
);
$context = stream_context_create($opts);
stream_context_set_default($context);
$url = 'http://example.com';
$response = file_get_contents($url);
print($response);
이 코드는 stream_context_set_default() 함수를 사용하여 HTTP 요청을 보내는 방법을示しています. $opts 배열에 HTTP 요청의 옵션을 설정하고, stream_context_create() 함수를 사용하여 stream context를 생성합니다. 그리고 stream_context_set_default() 함수를 사용하여 stream context의 기본값을 설정합니다. 마지막으로 file_get_contents() 함수를 사용하여 HTTP 요청을 보내고, 응답을 출력합니다.
2025-06-17 08:18