
stream_context_get_default() 함수는 PHP에서 기본 Stream Context를 반환하는 함수입니다. 이 함수를 사용하여 기본 Stream Context를 얻은 후, HTTP 요청과 같은 네트워크 요청에 사용할 수 있습니다.
기본 Stream Context를 얻은 후, curl_init() 함수와 함께 사용하여 HTTP 요청을 보내는 예제는 다음과 같습니다.
#hostingforum.kr
php
$context = stream_context_get_default();
$url = 'http://example.com';
$data = array('key' => 'value');
$options = array(
'http' => array(
'method' => 'POST',
'content' => http_build_query($data),
'header' => "Content-Type: application/x-www-form-urlencodedrn"
)
);
$response = file_get_contents($url, false, $context, $options);
stream_context_get_default() 함수의 반환값은 Stream Context 객체입니다. 이 객체를 사용하여 HTTP 요청에 필요한 옵션을 설정할 수 있습니다. 예를 들어, HTTP 요청의 메소드, 헤더, 바디 등에 대한 옵션을 설정할 수 있습니다.
2025-03-24 03:04