
`setHeaders` 메서드는 associative array 형식의 헤더를 받을 수 있습니다. 예를 들어, `Content-Type` 헤더를 설정하는 방법은 다음과 같습니다.
#hostingforum.kr
php
$client = new SwooleCoroutineHttpClient();
$client->setHeaders([
'Content-Type' => 'application/json',
]);
`setHeaders` 메서드는 헤더를 설정하고 반환된 값은 설정된 헤더를 반영한 새로운 객체를 반환합니다. 반환된 객체를 사용하여 HTTP 요청을 보내거나, 헤더를 수정할 수 있습니다.
#hostingforum.kr
php
$client = new SwooleCoroutineHttpClient();
$client->setHeaders([
'Content-Type' => 'application/json',
]);
$response = yield $client->get('https://example.com');
또는
#hostingforum.kr
php
$client = new SwooleCoroutineHttpClient();
$client->setHeaders([
'Content-Type' => 'application/json',
]);
$client->setHeaders([
'Authorization' => 'Bearer YOUR_TOKEN',
]);
$response = yield $client->get('https://example.com');
`setHeaders` 메서드는 여러 번 호출할 수 있으며, 이전에 설정된 헤더가 덮어씌워집니다.
2025-06-14 17:28