Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Server returned HTTP response code: 400 for URL: http://...

807600Aug 21 2007 — edited Aug 22 2007
I am using this code to read a file from a server:
public static String websiteReader(String website)
{
	String wcontents = "";
    String nextLine;
    URL url = null;
    URLConnection urlConn = null;
    InputStreamReader  inStream = null;
    BufferedReader buff = null;
    try{
       // Create the URL obect that points
       // at the default file index.html
       url  = new URL(website );
       urlConn = url.openConnection();
      inStream = new InputStreamReader( 
                        urlConn.getInputStream());
        buff= new BufferedReader(inStream);
     
    // Read and print the lines from index.html
     while (true){
         nextLine =buff.readLine();  
         if (nextLine !=null){
          wcontents=wcontents+nextLine;
          //System.out.println(nextLine);
          
         }
         else{
        	 return(wcontents);
          //JLabel wlabel = new JLabel(wcontents);
          //JWindow wwindow = new JWindow();
          //wwindow.add(wlabel);
          //wwindow.setVisible(true);
          //try {Thread.sleep(5000);} catch (InterruptedException e){}
         }

     }
  } catch(MalformedURLException e){
    System.out.println("Please check the URL:" + 
                                        e.toString() );
    return("error1");
  } catch(IOException  e1){
   System.out.println("Can't read  from the Internet: "+ 
                                       e1.toString() ); 
   return("error2");
}
}
It works for most webpages but this one webpage that I try doesn't work. The server that the page is on is fine because I used the script to connect to other pages on it, even some in the same directory. But I cant get this one to work. It is just a simple php file that writes text to a file. Other php scripts have worked.

What can I do to stop the 400 error?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 19 2007
Added on Aug 21 2007
4 comments
492 views