The simplest and most straightforward to get started can be found in the reference documentation : http://hutool.mydoc.io/?t=216015
for an introduction to the HTTP protocol, please refer to the Web essay : http://www.cnblogs.com/jiangbei/p/6681215.html
Fed up with httpclient? That Hutool Httputil is worth a try!
First, Httputil
Quick Read use:
Send a GET request, including participation in a non-parametric
Example:
String url = "http://www.sogou.com"; MapNew hashmap<>(); Parammap.put ("Query", 10086); // no parameter GET request String result = httputil.get (URL); // GET request with a parameter String result2 = httputil.get (URL, parammap);
Corresponding Source:
/*** Send GET request * *@paramurlstring URL *@returnreturns the content, if only check the status code, only normal return "", not normal return null*/ Public Staticstring Get (String urlstring) {returnHttprequest.get (urlstring). Execute (). body (); } /*** Send GET request * *@paramurlstring URL *@paramparammap Post form data *@returnReturn Data*/ Public StaticString Get (String urlstring, map<string, object>Parammap) { returnHttprequest.get (urlstring). form (Parammap). Execute (). body (); }
View Code
Send a POST request
Here is an example of a direct reference to a document:
New Hashmap<>();p arammap.put ("City", "Beijing"); String result= Httputil.post ("https://www.baidu.com", Parammap); // file upload simply specify the key in the parameter (the default file), the value is set to the file object, for the user, the file upload and the normal form submission is no different parammap.put ("File", Fileutil.file ("d:\\ Face.jpg ")); String result= Httputil.post ("https://www.baidu.com", Parammap);
Corresponding Source:
/*** Send POST request * *@paramurlstring URL *@paramparammap Post form data *@returnReturn Data*/ Public StaticString post (String urlstring, map<string, object>Parammap) { returnhttprequest.post (urlstring). form (Parammap). Execute (). body (); } /*** Send POST request * *@paramurlstring URL *@paramparams post form data *@returnReturn Data*/ Public Staticstring Post (String urlstring, string params) {returnhttprequest.post (urlstring). Body (params). Execute (). body (); }
View Codesecond, HttpRequest and HttpResponse
Not content with a highly-defined tool class package, and want to have more custom requests and response processing, you can use HttpRequest and HttpResponse
Get started quickly:
String result2 = httprequest.post (URL) "Hutool http"). form (PARAMMAP) . Execute (). Body ( );
Include some of the package's constant header status, etc. see Source code
Other customizations are as follows:
HttpResponse's treatment will not be mentioned.
HTTP tool for "Hutool" Hutool Tool class--httputil