Sending a POST Request with Parameters From a Java Class



This example shows how to sent a POST request to a server with attached parameters. Two parameters are sent in the example code below, width and height.
We use the URL and URLConnection classes to open the connection to the destination. Then the output stream is retrieved by calling getOutputStream() on the URLConnection object.
With the output stream we can write the parameters and then start reading the response from the server using the input stream which we get by calling getInputStream() on the same URLConnection object.
We assume there will only be character based content returned from the server so we use the BufferedWriter to read the response line by line.







Search for more Java info on this site here:
Custom Search


Any thoughts or questions?