wood burning stoves
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

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
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

How to Send a Http request using Swing GUI

Sandeep R Kumar

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


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

Thanks,<br />Sandeep
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
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.
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

You could use the Apache Commons HttpClient...

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

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

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.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";


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

} catch (MalformedURLException ex) {
} catch (IOException ex) {

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
It's not a secret anymore!