*
The moose likes Swing / AWT / SWT and the fly likes How to Send a Http request using Swing GUI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to Send a Http request using Swing GUI" Watch "How to Send a Http request using Swing GUI" New topic
Author

How to Send a Http request using Swing GUI

Sandeep R Kumar
Greenhorn

Joined: Apr 24, 2007
Posts: 11
i am using swing GUI....when i click submit, a new thread should be created and the data in the form should be sent to a servlet as http request...and the servlet should update the database accordingly and send back a proper response back ....
someone please help me out...
thanks in advance

--------------------

Thanks,
San
[ April 24, 2007: Message edited by: Sandeep Kumar R ]

Thanks,<br />Sandeep
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41603
    
  55
Hello Sandeep-

Welcome to JavaRanch.

On your way in you may have missed that we have a policy on screen names here at JavaRanch. Basically, it must consist of a first name, a space, and a last name, and not be obviously fictitious. Since yours does not conform with it, please take a moment to change it, which you can do right here.

As to your question, you can use the java.net.HttpUrlConnection class for this, or -for more convenience and flexibility- the Jakarta Commons HttpClient library.


Ping & DNS - my free Android networking tools app
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

You could use the Apache Commons HttpClient...


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Sandeep R Kumar
Greenhorn

Joined: Apr 24, 2007
Posts: 11
Thanks Ulf Dittmer ...
rohit leeta
Ranch Hand

Joined: May 02, 2007
Posts: 49
Yes, HttpClient is very powerful. It comes with some examples too.


<a href="http://www.java-forums.org" target="_blank" rel="nofollow">Java Forums</a>
jad yuuu
Greenhorn

Joined: May 06, 2007
Posts: 8
Or you can do it the simple way:

try {

URL url = new URL("http://www.yourURL.com/login.php");
HttpURLConnection con =(HttpURLConnection) url.openConnection();


con.setDoInput(true);
con.setDoOutput(true);
con.setUseCaches(false);
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

DataOutputStream printout = new DataOutputStream(con.getOutputStream());

// This is the POST
String content ="email=jad939933@hotmail.com&pass=577383";


printout.writeBytes(content);
printout.flush();
printout.close();





DataInputStream input = new DataInputStream(con.getInputStream());
String str;
//Read the response
while (null != ((str = input.readLine()))) {
System.out.println(str);
}
input.close();


} catch (MalformedURLException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}

This is described in more details on http://www.gulany.com/?page_id=7
[ May 07, 2007: Message edited by: jad yuuu ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to Send a Http request using Swing GUI