Java Impersonation HTTP Request

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.