
SwooleHttpClient::setHeaders 메소드는 HTTP 요청에 포함할 수 있는 일반 헤더를 지원합니다.
- Accept
- Accept-Charset
- Accept-Encoding
- Accept-Language
- Authorization
- Cache-Control
- Connection
- Content-Type
- Date
- Expect
- Host
- If-Match
- If-Modified-Since
- If-None-Match
- If-Range
- If-Unmodified-Since
- Max-Forwards
- Pragma
- Proxy-Authorization
- Range
- Referer
- TE
- User-Agent
이 메소드는 HTTP 요청을 보낼 때 자동으로 설정된 헤더를 포함합니다.
예를 들어, Authorization 헤더를 설정한 후에는 HTTP 요청을 보낼 때 Authorization 헤더가 포함됩니다.
#hostingforum.kr
php
$client = new SwooleHttpClient('example.com', 80);
$client->setHeaders([
'Authorization' => 'Bearer YOUR_TOKEN'
]);
$client->setMethod('GET');
$client->on('response', function ($cli) {
echo $cli->body;
});
$client->send();
$client->close();
위의 예제 코드에서 Authorization 헤더를 설정한 후, HTTP GET 요청을 보낼 때 Authorization 헤더가 포함됩니다.
2025-03-06 07:58