Java - sending HTTP parameters via POST method easily

前端 未结 17 2069
借酒劲吻你
借酒劲吻你 2020-11-21 05:54

I am successfully using this code to send HTTP requests with some parameters via GET method

void sendRequest(String request)
{
            


        
17条回答
  •  庸人自扰
    2020-11-21 06:32

    I find HttpURLConnection really cumbersome to use. And you have to write a lot of boilerplate, error prone code. I needed a lightweight wrapper for my Android projects and came out with a library which you can use as well: DavidWebb.

    The above example could be written like this:

    Webb webb = Webb.create();
    webb.post("http://example.com/index.php")
            .param("param1", "a")
            .param("param2", "b")
            .param("param3", "c")
            .ensureSuccess()
            .asVoid();
    

    You can find a list of alternative libraries on the link provided.

提交回复
热议问题