
EventHttpRequest::sendReply 메서드를 사용하여 클라이언트에 응답을 보낼 때, 헤더에 대한 처리는 다음과 같이 할 수 있습니다.
1. 헤더 추가:
- sendReply 메서드의 첫 번째 인자로 HTTPResponse 객체를 전달합니다.
- HTTPResponse 객체의 setHeader 메서드를 사용하여 헤더를 추가합니다.
- 예시:
#hostingforum.kr
php
$httpResponse = new HTTPResponse();
$httpResponse->setHeader('Content-Type', 'text/html');
$http->sendReply($httpResponse);
2. 헤더 삭제:
- sendReply 메서드의 첫 번째 인자로 HTTPResponse 객체를 전달합니다.
- HTTPResponse 객체의 removeHeader 메서드를 사용하여 헤더를 삭제합니다.
- 예시:
#hostingforum.kr
php
$httpResponse = new HTTPResponse();
$httpResponse->removeHeader('Content-Type');
$http->sendReply($httpResponse);
3. 헤더 수정:
- sendReply 메서드의 첫 번째 인자로 HTTPResponse 객체를 전달합니다.
- HTTPResponse 객체의 setHeader 메서드를 사용하여 헤더를 수정합니다.
- 예시:
#hostingforum.kr
php
$httpResponse = new HTTPResponse();
$httpResponse->setHeader('Content-Type', 'text/html');
$http->sendReply($httpResponse);
4. 헤더 추가 및 삭제:
- sendReply 메서드의 첫 번째 인자로 HTTPResponse 객체를 전달합니다.
- HTTPResponse 객체의 setHeader 메서드를 사용하여 헤더를 추가합니다.
- HTTPResponse 객체의 removeHeader 메서드를 사용하여 헤더를 삭제합니다.
- 예시:
#hostingforum.kr
php
$httpResponse = new HTTPResponse();
$httpResponse->setHeader('Content-Type', 'text/html');
$httpResponse->removeHeader('Accept');
$http->sendReply($httpResponse);
2025-05-31 18:21