라이브러리

[PHP] EventHttpRequest::removeHeader - 요청 헤더에서 HTTP 헤더를 제거합니다.




EventHttpRequest::removeHeader

`EventHttpRequest`는 PHP의 EventLoop 라이브러리에 포함된 클래스로, HTTP 요청을 처리하는 데 사용됩니다. `removeHeader` 메소드는 HTTP 요청의 헤더를 삭제하는 데 사용됩니다.

사용 방법


`removeHeader` 메소드는 다음과 같은 형식으로 사용됩니다.

#hostingforum.kr
php

EventHttpRequest::removeHeader($request, $headerName)



* `$request`: HTTP 요청 객체
* `$headerName`: 삭제할 헤더의 이름

예제


다음 예제는 `EventHttpRequest::removeHeader` 메소드를 사용하여 HTTP 요청의 헤더를 삭제하는 방법을 보여줍니다.

#hostingforum.kr
php

use ReactHttpRequest;

use ReactHttpResponse;

use ReactEventLoopLoop;

use ReactEventLoopTimer;

use ReactHttpHttpRequest;



// EventLoop 객체 생성

$loop = Loop::get();



// HTTP 요청 객체 생성

$request = new HttpRequest('http://example.com', 'GET');



// HTTP 요청의 헤더 추가

$request->setHeader('User-Agent', 'Mozilla/5.0');



// HTTP 요청의 헤더 삭제

$request->removeHeader('User-Agent');



// HTTP 요청 객체를 사용하여 HTTP 요청을 보냅니다.

$loop->run(function () use ($request) {

    $client = new GuzzleHttpClient();

    $response = $client->send($request);

    echo $response->getBody()->getContents();

});



결과


위 예제를 실행하면, HTTP 요청의 헤더 중 `User-Agent` 헤더가 삭제된 후 HTTP 요청이 보내집니다. 이때, HTTP 요청의 헤더 목록은 다음과 같습니다.

#hostingforum.kr
bash

GET / HTTP/1.1

Host: example.com

Accept: */*



참고


* `EventHttpRequest` 클래스는 PHP의 EventLoop 라이브러리에 포함되어 있습니다.
* `removeHeader` 메소드는 HTTP 요청의 헤더를 삭제하는 데 사용됩니다.
* `$request` 객체는 HTTP 요청 객체를 나타냅니다.
* `$headerName`은 삭제할 헤더의 이름을 나타냅니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

  • 전체 10,077건 / 575 페이지

검색

게시물 검색