Re: get ResponseCode() and connect()



Hi,

what value of urlString are you using?

Is it definately in the form: "http://<hostname or IP>[:<port>]/<page
to request>"

Graham
Lead Senior Developer
Modern Security Solutions
http://www.modernsecuritysolutions.com

IveCal wrote:
Hello, I have getResponseCode and connect() prob here... I want to
connect then get the response code of the remote server. It's been
almost 12 hours but I havent been connected and the server has not
given me a response... I set the time out but it seems not to work..
(Time out is set to 10 seconds.) Here's my code:

System.setProperty( "sun.net.client.defaultReadTimeout",
Integer.toString( 10000 ) );

URL url = new URL(urlString);
URLConnection uc = url.openConnection();
HttpURLConnection hc = ((HttpURLConnection)uc);

hc.setRequestProperty("Accept","image/gif, image/x-xbitmap, image/jpeg,
image/pjpeg, application/x-shockwave-flash, */*");
.
.
.
uc.setRequestProperty("Content-Type","xml/html; charset=utf-8");

hc.setInstanceFollowRedirects(false);
hc.connect();

// -- Check if the response code.
if (HttpURLConnection.HTTP_OK == hc.getResponseCode() ||
HttpURLConnection.HTTP_MOVED_TEMP == hc.getResponseCode() )
{
System.out.println("(Success) Responce Code: "+hc.getResponseCode());
}
else
{
System.out.println("Responce Code: "+hc.getResponseCode());
}

// -- get headers
for (int counter=0; ; counter++)
{
String name = uc.getHeaderFieldKey(counter);
String value = uc.getHeaderField(counter);
System.out.println(name+": "+value);
}

If u think that there's nothing wrong with the connect and
getResponseCode, please help me with the time out thing. Thank you...

.



Relevant Pages

  • get ResponseCode() and connect()
    ... I have getResponseCode and connectprob here... ... connect then get the response code of the remote server. ... String name = uc.getHeaderFieldKey; ...
    (comp.lang.java.programmer)
  • Problem in Java class while using URL class
    ... Exception in thread "main" java.net.UnknownHostException: ... URL url = new URL; ... String line; ...
    (comp.lang.java.programmer)
  • Impersonation causes a server error
    ... This users has been created on the remote server, ... Cannot execute a program. ... An unhandled exception occurred during compilation using ... userToken, String cmd, String currentDir, TempFileCollection tempFiles, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: fgets PayPal
    ... it compares the line to the string ... and if that comparison fails it compares the line to the ... which didn't fix the underlying problem but at least allowed me to look. ... I'm unsure what the problem is other than it is not a problem with the the remote server, ...
    (comp.lang.php)
  • Accessing files and folders on remote server - SERVER ERROR
    ... This users has been created on the remote server, ... Cannot execute a program. ... An unhandled exception occurred during compilation using ... userToken, String cmd, String currentDir, TempFileCollection tempFiles, ...
    (microsoft.public.dotnet.framework.aspnet)