Sep 23

// Create query string

String queryString = "param1=" + 
   URLEncoder.encode(param1Value, "UTF-8");
queryString += "&param2=" +
   URLEncoder.encode(param2Value, "UTF-8");
    
// Make connection

URL url = new URL("http://www.objects.com.au/");
URLConnection urlConnection = url.openConnection();
urlConnection.setDoOutput(true);
OutputStreamWriter out = new OutputStreamWriter(
   urlConnection.getOutputStream());

// Write query string to request body

out.write(queryString);
out.flush();
    
// Read the response

BufferedReader in = new BufferedReader(
   new InputStreamReader(urlConnection.getInputStream()));
String line = null;
while ((line = in.readLine()) != null)
{
   System.out.println(line);
}
out.close();
in.close(); 

written by objects \\ tags: , , ,


One Response to “How do I send a POST request using Java?”

  1. Kaniyarasu Says:

    Very useful content…
    Thank You..

Leave a Reply

You must be logged in to post a comment.