
stream_context_create 함수는 HTTP 요청을 보내는 데 사용되는 함수로, 매개변수는 다음과 같습니다.
- options: 옵션 배열로, stream_context_create 함수의 동작을 제어합니다.
stream_context_create 함수의 매개변수 options은 다음과 같은 역할을 합니다.
- 'http' => array('method' => 'POST', 'header' => 'Content-Type: application/json'): HTTP 요청의 메서드와 헤더를 지정합니다.
- 'http' => array('content' => 'Hello, World!'): HTTP 요청의 본문 내용을 지정합니다.
- 'http' => array('version' => '1.1'): HTTP 요청의 버전을 지정합니다.
stream_context_create 함수를 사용하여 HTTP 요청을 보내는 예시는 다음과 같습니다.
#hostingforum.kr
php
$opts = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-Type: application/json',
'content' => json_encode(array('name' => 'John', 'age' => 30))
)
);
$context = stream_context_create($opts);
$url = 'https://example.com/api';
$response = file_get_contents($url, false, $context);
print_r(json_decode($response, true));
stream_context_create 함수를 사용하여 HTTP 요청을 보내는 방법에 대한 더 자세한 정보는 PHP의 stream_context_create 함수 문서를 참고하시기 바랍니다.
2025-06-03 15:50