How to use
HttpClientHttp://hc.apache.org/httpcomponents-client-ga/httpclient/dependency-info.html
//GetCloseablehttpclient httpclient = httpclients.Createdefault(); HttpGet HttpGet =New HttpGet("Http://targethost/homepage"); Closeablehttpresponse response1 = httpclient.Execute(HttpGet);Try{System. out.println(Response1.Getstatusline()); Httpentity entity1 = response1.getentity(); Entityutils.Consume(entity1);}finally{response1.Close();}//PostHttpPost HttpPost =New HttpPost("Http://targethost/login"); List <NameValuePair> Nvps =NewArrayList <NameValuePair> (); Nvps.Add(New Basicnamevaluepair("username","VIP")); Nvps.Add(New Basicnamevaluepair("Password","Secret")); HttpPost.setentity(New urlencodedformentity(Nvps)); Closeablehttpresponse Response2 = httpclient.Execute(HttpPost);Try{System. out.println(Response2.Getstatusline()); Httpentity Entity2 = Response2.getentity(); Entityutils.Consume(Entity2);}finally{Response2.Close();}
Easy to use method
fluent-hcHttp://hc.apache.org/httpcomponents-client-ga/fluent-hc/dependency-info.html
// getRequest.Get("http://targethost/homepage") .execute() .returnContent();// postRequest.Post("http://targethost/login") .bodyForm(Form.form().add("username", "vip").add("password", "secret").build()) .execute() .returnContent();
Java Impersonation HTTP Request