0

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";
           }
2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by NormR1
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.