Dear Wiki user, You have subscribed to a wiki page or wiki category on "Httpcomponents Wiki" for change notification.
The following page has been changed by OlegKalnichevski: http://wiki.apache.org/HttpComponents/HttpClientTutorial ------------------------------------------------------------------------------ These are parameters that be used to customize HTTP authentication process and behaviour of individual authentication schemes: + * '''http.protocol.handle-authentication''': defines whether authentication should be handled automatically. This parameter expects a value of type java.lang.Boolean. + - * '''http.auth.credential-charset''': Defines the charset to be used when encoding user credentials. This parameter expects a value of type java.lang.String. + * '''http.auth.credential-charset''': defines the charset to be used when encoding user credentials. This parameter expects a value of type java.lang.String. - + == Authentication scheme registry == HttpClient maintains a registry of available authentication scheme using AuthSchemeRegistry class. The following schemes are registered per default: @@ -1517, +1519 @@ httpclient.addRequestInterceptor(preemptiveAuth, 0); }}} - = Redirect handling = + = HTTP client = + HttpClient interface represents only the most basic contract for HTTP request execution. It imposes no restrictions or particular details on the request execution process and leaves the specifics of connection management, state management, authentication and redirect handling up to individual implementations. This should make it easier to decorate the interface with additional functionality such as response content caching. - Redirects are handled automatically, except those explicitly prohibited by the HTTP spec. - Redirects on POSTs and PUTs are converted to GET. - - == Redirect handler == + == HTTP client parameters == + + These are parameters that be used to customize the behaviour of the default HttpClient implementation: + + * '''http.protocol.handle-redirects''': defines whether redirects should be handled automatically. This parameter expects a value of type java.lang.Boolean. + + * '''http.protocol.reject-relative-redirect''': defines whether relative redirects should be rejected. This parameter expects a value of type java.lang.Boolean. + + * '''http.protocol.max-redirects''': defines the maximum number of redirects to be followed. The limit on number of redirects is intended to prevent infinite loops caused by broken server side scripts. This parameter expects a value of type java.lang.Integer. + + * '''http.protocol.allow-circular-redirects''': defines whether circular redirects (redirects to the same location) should be allowed. The HTTP spec is not sufficiently clear whether circular redirects are permitted, therefore optionally they can be enabled. This parameter expects a value of type java.lang.Boolean. + + * '''http.connection-manager.factory-class-name''': defines the class name of the default ClientConnectionManager implementation. This parameter expects a value of type java.lang.String. + + * '''http.virtual-host''': defines the virtual host name to be used in the {{{Host}}} header instead of the physical host name. This parameter expects a value of type HttpHost. + + * '''http.default-headers''': defines the request headers to be sent per default with each request. This parameter expects a value of type ava.util.Collection containing Header objects. + + * '''http.default-host''': defines the default host. The default value will be used if the target host is not explicitly specified in the request URI (relative URIs). This parameter expects a value of type HttpHost. + - Custom redirect handling. + == Automcatic redirect handling == + + HttpClient handles all types of redirects automatically, except those explicitly prohibited by the HTTP specification as requiring user intervention. Redirects on POST and PUT requests are converted to GET requests as required by the HTTP specification. + + == Default HTTP client and execution context == + + The DefaultHttpClient treats HTTP requests as immutable objects that are never supposed to change in the course of request execution. Instead, it creates a private mutable copy of the original request object, whose properties can be updated depending on the execution context. Therefore the final request properties such as the target host and request URI can be determined by examining the content of the local HTTP context after the request has been executed. + + {{{ + DefaultHttpClient httpclient = new DefaultHttpClient(); + + HttpContext localContext = new BasicHttpContext(); + HttpGet httpget = new HttpGet("http://localhost:8080/"); + HttpResponse response = httpclient.execute(httpget, localContext); + HttpHost target = (HttpHost) localContext.getAttribute( + ExecutionContext.HTTP_TARGET_HOST); + HttpUriRequest req = (HttpUriRequest) localContext.getAttribute( + ExecutionContext.HTTP_REQUEST); + + System.out.println("Target host: " + target); + System.out.println("Final request URI: " + req.getURI()); + System.out.println("Final request method: " + req.getMethod()); + }}} = Advanced topics = @@ -1534, +1575 @@ == Custom client connections == + class MyLineParser extends BasicLineParser { + + @Override + public Header parseHeader( + final CharArrayBuffer buffer) throws ParseException { + try { + return super.parseHeader(buffer); + } catch (ParseException ex) { + return new BasicHeader("invalid", buffer.toString()); + } + } + + } + + class MyClientConnection extends DefaultClientConnection { + + @Override + protected HttpMessageParser createResponseParser( + final SessionInputBuffer buffer, + final HttpResponseFactory responseFactory, + final HttpParams params) { + return new DefaultResponseParser( + buffer, + new MyLineParser(), + responseFactory, + params); + } + + } + + class MyClientConnectionOperator extends DefaultClientConnectionOperator { + + public MyClientConnectionOperator(final SchemeRegistry sr) { + super(sr); + } + + @Override + public OperatedClientConnection createConnection() { + return new MyClientConnection(); + } + + } + + class MyClientConnManager extends SingleClientConnManager { + + public MyClientConnManager( + final HttpParams params, + final SchemeRegistry sr) { + super(params, sr); + } + + @Override + protected ClientConnectionOperator createConnectionOperator( + final SchemeRegistry sr) { + return new MyClientConnectionOperator(sr); + } + + } + --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
