Results 1 to 4 of 4
  1. #1
    rockravi is offline Member
    Join Date
    Jul 2011
    Posts
    3
    Rep Power
    0

    Default 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

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    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.

  3. #3
    rockravi is offline Member
    Join Date
    Jul 2011
    Posts
    3
    Rep Power
    0

    Default 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

  4. #4
    rockravi is offline Member
    Join Date
    Jul 2011
    Posts
    3
    Rep Power
    0

Similar Threads

  1. Replies: 1
    Last Post: 04-01-2011, 08:48 PM
  2. Replies: 5
    Last Post: 11-21-2010, 02:08 PM
  3. Parameters
    By MIA6 in forum New To Java
    Replies: 2
    Last Post: 12-22-2009, 01:25 PM
  4. what code for not hitting enter?
    By tornbacchus in forum New To Java
    Replies: 4
    Last Post: 04-11-2009, 04:59 AM
  5. get parameters in jsp
    By cecily in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 08-05-2007, 04:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •