Sep 16

// 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.obiweb.com.au"+queryString);
URLConnection urlConnection = url.openConnection();
    
// Read the response

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

written by objects \\ tags: , , , ,


2 Responses to “How do I send a GET request using Java?”

  1. Tomek Says:

    out.close(); should not be there – there is no “out” stream opened

  2. objects Says:

    Thanks, have updated the post

Leave a Reply

You must be logged in to post a comment.