Execute Http method (post/get) : Http Client « Apache Common « Java

Execute Http method (post/get)

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HostConfiguration;
import org.apache.commons.httpclient.methods.GetMethod;

public class HttpClientPreferences {

 public static void main(String args[]) throws Exception {
      HttpClient client = new HttpClient();
      System.err.println("The User Agent before changing it is: " + client.getParams().getParameter("http.useragent"));
      client.getParams().setParameter("http.useragent","Browser at Client level");
      System.err.println("Client's User Agent is: " + client.getParams().getParameter("http.useragent"));
      GetMethod method = new GetMethod("http://www.google.com");
      method.getParams().setParameter("http.useragent","Browser at Method level");
      }catch(Exception e) { 
      }finally { 
      System.err.println("Method's User Agent is: " +  method.getParams().getParameter("http.useragent"));


HttpClientPreferences.zip( 336 k)

Related examples in the same category

1.Get Http methods
2.Get Http client parameters
3.Http Client Simple Demo
4.Get allowed http methods
5.Http post method Example
6.Connect Method Example For Proxy Client
7.Basic Authentication Execute JSP Method
8.Basic Authentication For JSP Page
9.Basic Authentication Get JSP Method Return Code
10.Get Cookie value and set cookie value
11.Using Http Client Inside Thread