2014-09-18 2 views
0

org.apache.http.client.HttpClient은 대상 호스트와 요청 매개 변수를 취하는 execute 메서드를 지정합니다.HttpClient가 지나치게 지정된 경로를 어떻게 처리합니까?

/** 
* Executes a request to the target using the default context. 
* 
* @param target the target host for the request. 
*     Implementations may accept <code>null</code> 
*     if they can still determine a route, for example 
*     to a default target or by inspecting the request. 
* @param request the request to execute 
* 
* @return the response to the request. This is always a final response, 
*   never an intermediate response with an 1xx status code. 
*   Whether redirects or authentication challenges will be returned 
*   or handled automatically depends on the implementation and 
*   configuration of this client. 
* @throws IOException in case of a problem or the connection was aborted 
* @throws ClientProtocolException in case of an http protocol error 
*/ 
HttpResponse execute(HttpHost target, HttpRequest request) 
    throws IOException, ClientProtocolException; 

나는 DefaultHttpClientDefaultRequestDirector 소스 코드에 탐구 한, 그것은 간단한 execute(HttpRequest request) 방법은 HttpHost 객체에 요청하고 HttpRequest에 객체를 분리하고 실제로 (더 지정된 메소드에 호출을 전달 명백하게되었다 , HttpContext 개체도 허용하는 -하지만 지금은 상황에 신경 쓰지 않습니다.)

요청 및 호스트 모두 URI를 허용 할 수 있으므로 내 최종 질문은 어떻게 결정됩니까? 둘 다 절대 URI가 포함되어 있습니까? 충돌하는 경우? 둘 다 부분 경로가 있습니까?

답변

1

HttpHost물리적 인 종점을 나타낸다. URI의 권한 부분 (체계, 호스트 및 포트) 만 포함합니다. 경로가 없습니다. 요청 URI은 잠재적으로 가상의이 될 수있는 리소스를 나타냅니다. 갈등은 없을 수 있습니다. HttpHost 명시 적으로 요청 URI의 권한 부분을 부여되지 않은 경우에만 물리적 엔드 포인트를 것으로 간주됩니다

HttpHost = http://www.google.com:-1 
Request URI = http://www.google.ch/stuff 

다음과 같은 메시지 작성

TCP

localhost:<random> -> www.google.com:80 
가 발생합니다 예를 들어

HTTP

GET /stuff HTTP/1.1 
Host: www.google.ch 

AbstractHttpClient.determineTarget 개인 도우미 방식에서이 동작을 볼 수 있습니다. 4.0과 4.3.5를 근본적으로 변경 함에도 불구하고 을 제공하지 않는 execute 변형의 URI에서 스키마, 호스트 및 포트 만 추출합니다. 대상과 요청이 최종 경로로 다시 구성되는 코드는 더 복잡하지만 HttpRoute, HttpRoutePlanner 및 HttpRequest impl 메서드를 자세히 읽으면 HTTP 호스트와 경로에서 오는 host 또는 hostTarget을 명확히 나타냅니다. 매개 변수 및 단편)은 HttpRequest에서 가져온 로컬 부분에서 가져옵니다.

+0

감사합니다. 내가 그랬 으면 좋겠다. 그리고 편집에서 언급 된 관련'Http ... '클래스들을 조금 더 파고 들자면, 나는 당신의 설명이 항상 사실이라고 확신한다. 적어도 DefaultHttpClient 클래스는 . –