HTTP tool for "Hutool" Hutool Tool class--httputil

Source: Internet
Author: User

  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

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.