Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

request time out trouble

 
sksharma sharma
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dear all ,
i have made a simple program that read the contents of an HTML page , but i am facing a small problem . the problem is, when i run the program on my system then it works properly means it shows us the contents of the desired web page, but when i run it on other system that uses different proxy then it throws error

java.net.ConnectException: Connection timed out: connect

can any body help me out
This is the sample of my code



/**
* Created by IntelliJ IDEA.
* User: varungoyal
* Date: Feb 9, 2006
* Time: 5:51:34 PM
* To change this template use File | Settings | File Templates.
*/
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;


public class SendPostRequest {
private static InputStream stream = null;
public static void main(String args[]){
execute();
}
public static void execute(){

try {
System.out.println("CONTROL HERE ");
URL myURL = new URL("http://yahoo.com");
HttpURLConnection urlc = (HttpURLConnection) myURL.openConnection();
urlc.setRequestMethod("POST");
urlc.connect();
System.out.println("GET RESPONSE CODE =====> "+urlc.getResponseCode());
try {
stream = urlc.getInputStream();
int size= stream.available();
while(size!=0) {
byte data[] = new byte[size];
int num_read = stream.read(data);
byte[] actualdata = new byte[num_read];
System.arraycopy(data,0,actualdata,0,num_read);
String webData=new String(actualdata);
System.out.println(webData);

if(stream.read()== -1) {
return;
}
}
}
catch(Exception e){
System.out.println("________________ error while reading _____________________");
}

}
catch (IOException ex) {
ex.printStackTrace();
System.out.print("ERROR IN REQUESTING URL ");

}

}
}
 
PJ Crump
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you were using HttpClient then you would just say
httpClientInstance.getHostConfiguration().setProxy("proxyname");
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic