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?