Hi again! Pls some one help me to find out what is the problem with this code....

import java.io.*;
import java.net.*;
public class NewClass2
{
    public static void main (String args[])
    {
    try
    {
        // Construct data
       
        // Send data
        String data="Something";
        URL url = new URL("http://www.google.co.uk/");
        URLConnection conn = url.openConnection();
        conn.setDoOutput(true);
        conn.setDoInput(true);
        OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
        wr.write(data);
        wr.flush();

        // Get the response
        BufferedReader in = new BufferedReader (new InputStreamReader(conn.getInputStream ()));
          String temp,response="";
          while ((temp = in.readLine()) != null){
            response += temp + "\n";
           }
          temp = null;

          System.out.println("Server response:\n'" + response + "'");
        wr.close();

        in.close();
    }
    catch (Exception e)
    {

    }
    }
}

.....
So the build was successful but didn't get anything back from the

while ((temp = in.readLine()) != null){
            response += temp + "\n";
           }

How do you know if anything was returned by the readLine()?
Add a println("temp=" + temp +<") statement immediately after the readLine() to show what was read.
Maybe it has read a 100 lines and is waiting for 101st.

Also you could use the available() method to see if there is anything to read.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.