• 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

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();
 
There is no "i" in denial. Tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic