Results 1 to 4 of 4
Thread: Hitting URL with parameters
- 07-28-2011, 06:01 PM #1
Member
- Join Date
- Jul 2011
- Posts
- 3
- Rep Power
- 0
Hitting URL with parameters
Hi i have a URL with Some parameters....
I m unable to construct the URL with parameters and to connect it...
I m giving the code below....
Please any some one help me out..............
finally i need to construct URL=http://www.sms.com/SendingSms.aspx?userid=demo&pass=welc@123 like this.......
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;
public class URLDemo
{
public static void main(String args[])
{
HttpURLConnection con = null;
URL hp=null;
try
{
hp = new URL("http://www.sms.com/SendingSms.aspx");
con = (HttpURLConnection)hp.openConnection();
con.addRequestProperty("userid","demo");
con.addRequestProperty("pass","welc@123");
con.setRequestMethod("GET");
con.setDoOutput(true);
con.setReadTimeout(10000);
con.connect();
int res=con.getResponseCode();
String s=con.getResponseMessage();
System.out.println("URL"+con.getURL());
System.out.println("Response Code:"+res+"Response Msg:"+s);
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
catch (ProtocolException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
catch (IllegalStateException e)
{
e.printStackTrace();
}
finally
{
con.disconnect();
con = null;
}
}//main
}//class
- 07-28-2011, 07:53 PM #2
What URL does your code currently generate?
Put the URL you want in the URL class constructor.
The request properties are going into the HTTP request header.
Here is a sample of what is received by localhost with the full URL and your request properties set:
GET /SendingSms.aspx?userid=demo&pass=welc@123 HTTP/1.1
userid: demo
pass: welc@123
User-Agent: Java/1.6.0_25
Host: 127.0.0.1:8080
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive
Last edited by Norm; 07-28-2011 at 08:04 PM.
- 07-29-2011, 07:40 AM #3
Member
- Join Date
- Jul 2011
- Posts
- 3
- Rep Power
- 0
Re:
Just i need to hit the URL with parameters.....
i need to construct URL and need to pass it to the HttpURLConnection(URL)
constructor....help me out to get this type of URL with parameters
- 07-29-2011, 09:44 AM #4
Member
- Join Date
- Jul 2011
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
how to open a folder when hitting the button (like opening a my documents)
By ashin in forum SWT / JFaceReplies: 1Last Post: 04-01-2011, 08:48 PM -
how to pass parameters from a method to another which accepts to parameters?possible?
By amrmb09 in forum Advanced JavaReplies: 5Last Post: 11-21-2010, 02:08 PM -
Parameters
By MIA6 in forum New To JavaReplies: 2Last Post: 12-22-2009, 01:25 PM -
what code for not hitting enter?
By tornbacchus in forum New To JavaReplies: 4Last Post: 04-11-2009, 04:59 AM -
get parameters in jsp
By cecily in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 08-05-2007, 04:29 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks