Code example for HttpUriRequest

Methods: abort, getParams

0
						"Please specify a HttpClient instance to use for this request."); 
			} 
			 
			request = createFinalRequest();
			 
			final HttpResponse response = client.execute(request);
 
			Log.v(TAG, "res= "+response);
			return response;
		} 
 
		/** 
		 * Executes this request and returns the content body of the result as a 
		 * String. If no response body exists, this returns {@code null}. 
		 *  
		 * @return the response body as a String or {@code null} if 
		 *         no response body exists. 
		 * @throws IOException if an error occurs while execution 
		 */ 
		public String asString() throws IOException {
			final HttpResponse response = asResponse();
			final HttpEntity entity = response.getEntity();
			if (entity == null) { 
				return null; 
			} 
			 
			return EntityUtils.toString(entity, charset);
		} 
 
		/** 
		 * Executes this request and saves the response stream to a file. The 
		 * stream is going to be copied if and only if the response was 
		 * successful ({@code 2xx}) and a response body exists. If the response 
		 * code was {@code >= 300}, a {@link FileNotFoundException} is thrown. 
		 * If no body exists, this returns {@code false} and no exception is 
		 * thrown. 
		 *  
		 * @param target the file in which the stream should be copied. 
		 * @return {@code true} if the stream was copied successful to the file, 
		 *         otherwise {@code false}. 
		 * @throws IOException if an error occurs while execution 
		 * @throws FileNotFoundException if the response code was {@code >= 300}. 
		 */ 
		public boolean asFile(final File target) throws IOException {
			final HttpResponse response = asResponse();
			return new FileResponseHandler(target, url).handleResponse(response);
		} 
 
		/** 
		 * Executes this request and processes the response using the given 
		 * response handler. 
		 *  
		 * @param handler the response handler 
		 * @return the response object generated by the response handler. 
		 * @throws IOException if an error occurs while execution 
		 */ 
		public <T> T as(final ResponseHandler<? extends T> handler) throws IOException {
			if (handler == null) {
				throw new NullPointerException("ResponseHandler must not be null.");
			} 
			 
			final HttpResponse response = asResponse();
			return handler.handleResponse(response);
		} 
 
		/** 
		 * Executes this request and aborts immediately after execution using 
		 * the {@linkplain HttpUriRequest#abort() abort} method of this request. 
		 *  
		 * @throws IOException if an error occurs while execution 
		 */ 
		public void throwAwayResponse() throws IOException { 
			asResponse(); 
			request.abort();
		} 
 
		/** 
		 * Executes this request and consumes any available content on the 
		 * response stream. 
		 *  
		 * @throws IOException if an error occurs while execution 
		 */ 
		public void consumeResponse() throws IOException { 
			final HttpResponse response = asResponse();
			final HttpEntity entity = response.getEntity();
			if (entity == null) { 
				return; 
			} 
			 
			entity.consumeContent();
		} 
 
		abstract protected HttpUriRequest createRequest() throws IOException;
 
		protected String getUrl() {
			return url;
		} 
		 
		protected List<Header> getHeaders() {
			if (headers == null) {
				headers = new ArrayList<Header>();
			} 
			return headers;
		} 
		 
		protected List<RequestCustomizer> getCustomizers() {
			if (customizers == null) {
				customizers = new ArrayList<RequestCustomizer>();
			} 
			return customizers;
		} 
		 
		protected HttpClient getClient() {
			return client;
		} 
 
		private HttpUriRequest createFinalRequest() throws IOException {
			final HttpUriRequest request = createRequest();
			 
			applyHeaders(request);				
			if (followRedirects != null) {
				HttpClientParams.setRedirecting(request.getParams(), followRedirects);
			} 
			applyCustomizers(request);
			 
			return request;
		}