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

how to create httpurlconnection

 
rahul karwal
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ppl,
I am a new to java, i am trying to create an applet which takes the user informataion such as name,email address and there interest and want to send that data to the server. i tried creating a socket connection but i got a security error, then i was suggested to open a httpUrlConnection. but that class is abstract so i cant create a object of that class to open a connection.......and another question is what kind of connection should a server be having to communicate with the httpurlconnection can it serversocket or ???.does anyone hava a similar example of this so that i can see how to open a httpconnection connection is established on teh client side and what kind of connection a server can be having.Moreover is there any easier way to send the data to the server without creating a http connection.
import java.io.*;
import java.net.*;
public class client extends HttpURLConnection{
public static void main(String args[]) throws Exception{
URL url = new URL("HTTP","leech",6789,"hello");
client httpconn = new client (url);
}

public client(URL u){
super(u);
}
public void connect(){


}
public void disconnect(){


}

public boolean usingProxy(){

return false;
}



}
thanks
aziz
 
Tim Holloway
Saloon Keeper
Posts: 18362
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any sort of network connection will throw a security exception if you're an unsigned applet (the default) and attempting to connect to a server other than the one that the applet was downloaded from.
Actually, the HttpURLConnection is designed to handle all the complexities of the HTTP protocol in as simple a manner as possible - things like headers and cookies are either magically done for you or implemented via simple method calls.
 
Nishith Prabhakar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alternatively,
Call a servlet on the same server as the applet ... send the data to this servlet ... and let this servlet call the server you are trying to access ...
HttpURLConnection will work when the applet and servlet are on the same server. Basically, restrictions can be overcome easily by hosting a servlet with the applet and letting the servlet access resources not allowed to the applet.
------------------
-----BEGIN GEEK CODE BLOCK-----
Version 3.1
GCS/CC/IT d->+ s: a-- C++(++++)$ ULH+>++++ P>P++ L+(++)$ E+ W+(++) N+>++ o? K? w++>+++
O--- !M V? PS+(-) !PE Y+ PGP->+ !t !5 !X R->* !tv b+>+++ DI !D
G+(++) e>+++ h@ !r y-*
------END GEEK CODE BLOCK------
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic