• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

HttpURLConection and ClassCastException

 
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
 
Sheriff
Posts: 9099
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
Boost this thread!