Sending HTTP POST Request In Java

后端 未结 8 1307
清歌不尽
清歌不尽 2020-11-21 11:17

lets assume this URL...

http://www.example.com/page.php?id=10            

(Here id needs to be sent in a POST request)

I want to se

相关标签:
8条回答
  • 2020-11-21 11:55

    Call HttpURLConnection.setRequestMethod("POST") and HttpURLConnection.setDoOutput(true); Actually only the latter is needed as POST then becomes the default method.

    0 讨论(0)
  • 2020-11-21 11:57

    A simple way using Apache HTTP Components is

    Request.Post("http://www.example.com/page.php")
                .bodyForm(Form.form().add("id", "10").build())
                .execute()
                .returnContent();
    

    Take a look at the Fluent API

    0 讨论(0)
提交回复
热议问题