Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: dohttppost error

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Exclamation dohttppost error

    hi;
    Some time ago I've started writing a program that the ability to login to the website and submitting website form to be had but i got some error i use this cod:
    PHP Code:
     public HttpURLConnection dohttppost(URL targetUrlString contentString cookiethrows IOException {
            
    HttpURLConnection urlConnection null;
            
    HttpURLConnection urlConnection2 null;
            
    DataOutputStream dataOutputStream null;
            
    DataOutputStream dataOutputStream2 null;
            try {


                
    urlConnection = (HttpURLConnection) (targetUrl.openConnection());
                
    urlConnection.setDoInput(true);
                
    urlConnection.setDoOutput(true);

                
    urlConnection.setRequestProperty("Cookie"cookie);
                
    urlConnection.setRequestProperty("Content-Type"POST_CONTENT_TYPE);
                
    urlConnection.setRequestProperty("User-Agent""Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3");
                
    urlConnection.setRequestProperty("Connection""Keep-Alive");
                
    HttpURLConnection.setFollowRedirects(true);
                
    urlConnection.setRequestMethod("POST");
                
    dataOutputStream = new DataOutputStream(urlConnection.getOutputStream());
                
    dataOutputStream.writeBytes(content);
                
    dataOutputStream.flush();
                
    dataOutputStream.close();
                return 
    urlConnection;
            } catch (
    IOException ioException) {
                
    System.out.println("I/O problems while trying to do a HTTP post.");
                
    ioException.printStackTrace();
                if (
    dataOutputStream != null) {
                    try {
                        
    dataOutputStream.close();
                    } catch (
    Throwable ignore) {
                    }
                }
                if (
    urlConnection != null) {
                    
    urlConnection.disconnect();
                }

                throw 
    ioException;
            }
        } 
    I already login to the site and I want to submitted site form so i use this cod:
    PHP Code:
    HttpURLConnection urlConnection dohttppost(new URL("http://tv.station.ir/ab.php"), contentcookie); 
    and wesite url is: tv.station.ir/ab.php
    Website forms like the following picture:

    When I'm using the dohttppost method of operation Does correct but that page refers to another page form to Approving or final accepting like the following:
    wesite url refers to: tv.station.ir/ab.php
    again and form like the following picture:

    now when i use this cod i got error:
    PHP Code:
    URL ul urlConnection.getURL();
    HttpURLConnection urlConnection2 dohttppost(ulScontentcookie); 
    but confirm form does not work!!!
    and i can not send forms good because the forms has confirm form and refer to another page.
    plz help me what should i do?
    Last edited by Mohandes; April 3rd, 2011 at 04:54 AM.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: dohttppost error

    i got some error
    What error? Without all the information we're left guessing.

    This thread has been cross posted here:

    http://www.java-forums.org/new-java/41754-dohttppost-error.html

    Although cross posting is allowed, for everyone's benefit, please read:

    Java Programming Forums Cross Posting Rules

    The Problems With Cross Posting

    Please read: http://www.javaprogrammingforums.com...s-posting.html

    Last edited by copeg; April 3rd, 2011 at 09:51 AM.

  3. The Following User Says Thank You to copeg For This Useful Post:

    Mohandes (April 3rd, 2011)

  4. #3
    Junior Member
    Join Date
    Mar 2011
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: dohttppost error

    Quote Originally Posted by copeg View Post
    What error? Without all the information we're left guessing.
    hi thx.
    i can not set user agent or set cookies setpropety for urlConnection to send confirm Form again!
    and i can not post confirm form!
    if i try do that i got this error:
    UrlConnection already connected or can not Setproperty again!!! but user agent is not set in the secound post!
    Last edited by Mohandes; April 3rd, 2011 at 12:04 PM.