Results 1 to 13 of 13
Like Tree1Likes
  • 1 Post By DarrylBurke

Thread: HttpURLconnection POST request

  1. #1
    chopficaro is offline Member
    Join Date
    May 2012
    Posts
    14
    Rep Power
    0

    Default HttpURLconnection POST request

    i want to send a request with post data
    i tried looking it up for myself, but this page has alot of missing information
    HTTP POST Basics
    when i compiled it the compiler didnt know what connector.open was or httprequest was etc
    Last edited by chopficaro; 05-20-2012 at 11:17 AM.

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

    Default Re: HttpURLconnection POST request

    the compiler didnt know
    Please post the full text of any error messages.

    Did you spell the class names and method names correctly?
    Did you have the needed import statements?
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    chopficaro is offline Member
    Join Date
    May 2012
    Posts
    14
    Rep Power
    0

    Default Re: HttpURLconnection POST request

    i copied and pasted it exactly so everything was spelled correctly, but then i started messing with it because it wasnt working, i replaced HttpConnection with HttpURLConnection and stuff
    maybe i dont have the "connector" import statement, but i cant find any class called connector
    it looks like connector is an object tho and they dont show the instanciation of the class
    they dont show the instanciation of alot of classes actually...
    i just want to make a POST request this shouldnt be so hard

    InputScreen.java:302: cannot find symbol
    symbol : variable Connector
    location: class InputScreen
    conn = (HttpURLConnection) Connector.open( check
    URL );

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

    Default Re: HttpURLconnection POST request

    Where is the class: Connector defined?
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  6. #6
    chopficaro is offline Member
    Join Date
    May 2012
    Posts
    14
    Rep Power
    0

    Default http request with POST data

    i want to send a request with post data
    i tried looking it up for myself, but this page has alot of missing information
    HTTP POST Basics
    when i compiled it the compiler didnt know what connector.open was or httprequest was etc
    i copied and pasted it exactly so everything was spelled correctly, but then i started messing with it because it wasnt working, i replaced HttpConnection with HttpURLConnection and stuff
    maybe i dont have the "connector" import statement, but i cant find any class called connector
    it looks like connector is an object tho and they dont show the instanciation of the class
    they dont show the instanciation of alot of classes actually...
    i do not know where the class connector is defined
    i just want to make a POST request this shouldnt be so hard

    InputScreen.java:302: cannot find symbol
    symbol : variable Connector
    location: class InputScreen
    conn = (HttpURLConnection) Connector.open( check
    URL );

    Edit: sorry for the re post but someone locked the other thread, probably because im new and they think im a spam bot, but nope im just a guy who wants to make a post request
    Last edited by chopficaro; 05-20-2012 at 09:58 PM.

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,197
    Rep Power
    19

    Default Re: HttpURLconnection POST request

    No, nobody thought you were a spambot. But there were a series of spambot posts to your thread, so the thread was locked temporarily.

    I've merged your new post here.

    db
    Fubarable likes this.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

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

    Default Re: HttpURLconnection POST request

    Where is the class: Connector defined?
    If you don't understand my response, don't ignore it, ask a question.

  9. #9
    chopficaro is offline Member
    Join Date
    May 2012
    Posts
    14
    Rep Power
    0

    Default Re: HttpURLconnection POST request

    i dont know where the class connector is defined
    thats what ive been trying to say
    i just saw the code on the link i posted, but i cant find connector class on the oracle site, so i cant type in the import statement
    why did they not show the instanciation or import in the guide i posted idk

  10. #10
    chopficaro is offline Member
    Join Date
    May 2012
    Posts
    14
    Rep Power
    0

    Default Re: HttpURLconnection POST request

    i would show u my code but it is so messed up from dumb stuff ive done to try to fix it
    can someone just explain the missing information to me?
    why is it so hard to make a post request????

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

    Default Re: HttpURLconnection POST request

    Perhaps you should start with a new version that doesn't copy code that's missing parts.

    Try using the URL openConnection() method. Print out the value it returns.
    Last edited by Norm; 05-21-2012 at 01:51 AM.
    If you don't understand my response, don't ignore it, ask a question.

  12. #12
    chopficaro is offline Member
    Join Date
    May 2012
    Posts
    14
    Rep Power
    0

    Default Re: HttpURLconnection POST request

    ok i looked up url openConnection(), it said to make a post request do this
    Java Code:
    String urlParameters = "param1=a&param2=b&param3=c";
    String request = "http://example.com/index.php";
    URL url = new URL(request); 
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();           
    connection.setDoOutput(true);
    connection.setDoInput(true);
    connection.setInstanceFollowRedirects(false); 
    connection.setRequestMethod("POST"); 
    connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); 
    connection.setRequestProperty("charset", "utf-8");
    connection.setRequestProperty("Content-Length", "" + Integer.toString(urlParameters.getBytes().length));
    connection.setUseCaches (false);
    
    DataOutputStream wr = new DataOutputStream(connection.getOutputStream ());
    wr.writeBytes(urlParameters);
    wr.flush();
    wr.close();
    connection.disconnect();
    but the last few lines dont make any sense. how do i get the content returned by the post request as a string?

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

    Default Re: HttpURLconnection POST request

    "it" said.
    Who is the "it"?

    Get the input stream and read from that.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. HTTP POST Request (HttpURLConnection)
    By Dude in forum Networking
    Replies: 17
    Last Post: 07-15-2011, 11:11 PM
  2. POST request using HttpUrlConnection
    By turk in forum Networking
    Replies: 3
    Last Post: 07-06-2011, 04:36 PM
  3. POST request using HttpUrlConnection
    By turk in forum Networking
    Replies: 2
    Last Post: 07-06-2011, 04:29 PM
  4. Replies: 4
    Last Post: 10-15-2008, 01:59 PM
  5. First post as per request
    By happyknappy in forum Introductions
    Replies: 3
    Last Post: 07-30-2008, 01:33 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
  •