Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HttpURLConection and ClassCastException

 
lusha tak
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I have written an applet in which i am trying to connect to a server using

URL u = new URL("http://www.google.com/");
System.out.println("Host...."+u.getHost());
HttpURLConnection uc = (HttpURLConnection) u.openConnection();
retval=uc.getResponseCode();

The code throws java.lang.ClassCastException: com/ms/net/wininet/http/HttpURLConnection
at run time. The reason i found is that different browser and their versions do not to return the same java.net.HttpURLConnection on URL.openConnection. e.g. in case of IE it returns com.ms.net.wininet.http.HttpURLConnection.

Since the applet code will run on different browser with different version. Is there a way around to solve this issue. :roll:
Also how to check for the connection with a specific remote server if the client browser setting is through proxy??
Thankyou for ur interest and time
Best Regards
Lusha
 
Marilyn de Queiroz
Sheriff
Posts: 9068
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this instead ...

URL u = new URL("http://www.google.com/");
URLConnection con = u.openConnection();
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic