Results 1 to 9 of 9
Like Tree1Likes
  • 1 Post By Petr

Thread: http post

  1. #1
    cino is offline Member
    Join Date
    Jun 2011
    Posts
    5
    Rep Power
    0

    Default http post

    Hi ,
    I am looking on how i can send a Http post in java.. pls help me a bit urgent .. thanks

  2. #2
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    618
    Rep Power
    4

    Default

    Like that.
    Java Code:
        private String sendPostRequest(String data) throws Exception {
            URLConnection conn = new URL(url).openConnection();
            conn.setDoOutput(true);
            OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream());
            writer.write(data);
            writer.flush();
            StringBuffer answer = new StringBuffer();
            BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
            String line;
            while ((line = reader.readLine()) != null) {
                answer.append(line);
            }
            writer.close();
            reader.close();
            return answer.toString();
        }
    I guess you are so lazy that can't find this in google.
    Last edited by Petr; 06-13-2011 at 02:53 PM.
    cino likes this.
    Skype: petrarsentev
    http://TrackStudio.com

  3. #3
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,335
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by cino View Post
    Hi ,
    I am looking on how i can send a Http post in java.. pls help me a bit urgent .. thanks
    I bet you haven't read the API documentation for the HttpURLConnection class.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    cino is offline Member
    Join Date
    Jun 2011
    Posts
    5
    Rep Power
    0

    Default

    Thanks Dude,
    how i can get this value in php..?
    if let say ..
    $hp_number = $_POST['key1'];
    echo $hp_number;

    where i must give the "key1" in java....?

  5. #5
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    618
    Rep Power
    4

    Default

    like that, dude ))
    Java Code:
    String data = "key1=2&key2=2&key3=3";
    ...
    sendPostRequest(data);
    Skype: petrarsentev
    http://TrackStudio.com

  6. #6
    cino is offline Member
    Join Date
    Jun 2011
    Posts
    5
    Rep Power
    0

    Default

    Dude,my eclipse is returning that value.. but php page can't echo that value ....its not getting posted in the php variable..
    thanks

  7. #7
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    618
    Rep Power
    4

  8. #8
    cino is offline Member
    Join Date
    Jun 2011
    Posts
    5
    Rep Power
    0

    Default

    cheers buddy...atlast we made it...thank you so much.....we owe you a beer...:)

  9. #9
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    618
    Rep Power
    4

Similar Threads

  1. http post login
    By Billoto in forum Networking
    Replies: 0
    Last Post: 10-03-2010, 04:06 PM
  2. HTTP POST over sockets
    By DC200 in forum Networking
    Replies: 2
    Last Post: 09-19-2010, 03:00 PM
  3. HTTP Post
    By erics44 in forum New To Java
    Replies: 0
    Last Post: 03-22-2010, 01:01 PM
  4. No location on http post
    By malandro95 in forum Advanced Java
    Replies: 2
    Last Post: 03-09-2010, 02:49 PM
  5. SOAP over HTTP/POST
    By sabatier in forum NetBeans
    Replies: 0
    Last Post: 07-10-2007, 08:04 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
  •