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 2 of 2

Thread: HTTP post to html servlet

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default HTTP post to html servlet

    Hello i have a task to create a client that can remotely add entries to blog. By doing this i need to call HTTP POST and put proper content to forms ( at least i guess so)
    blog
    HTML Code:
    url is:someblog.com/blog.jsp?action=new
    html of a servlet that is responsible to manually add entries:
    HTML Code:
    <form class="MultiFile-intercepted" enctype="multipart/form-data" method="post" onsubmit="return checkAnomalyFields();" action="dodajN.html">
    <table style="border-weight: 0px">
    <tbody>
    <tr>
    <tr>
    <td id="wybory">
    <select id="typ" onchange="typeSelected()" size="1" name="typuId">
    </td>
    <td>
    </tr>
    <tr>
    <tr>
    <td colspan="2">
    <textarea cols="60" rows="10" name="opis">Opis nieprawidłowości</textarea>
    </td>
    </tr>
    <tr> </tr>
    <tr>
    <td>
    <div id="fileDiv">
    <div id="MultiFile1_wrap" class="MultiFile-wrap">
    <input class="multi MultiFile-applied" type="file" maxlength="5" accept="jpg" name="undefined" value="">
    <div id="MultiFile1_wrap_list" class="MultiFile-list"></div>
    </div>
    </div>
    </td>
    </tr>
    to make a request i use:

    HttpClient httpclient = new MyHttpClient(Send.this);
                    HttpPost httppost = new HttpPost("https://blog.com/blog.jsp?action=new");
                    // Add your data
                    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3);
                    nameValuePairs.add(new BasicNameValuePair("typuId", "Wysypisko"));
                    nameValuePairs.add(new BasicNameValuePair("statusuId", "Do moderacji"));
                    nameValuePairs.add(new BasicNameValuePair("os", "android"));
                    nameValuePairs.add(new BasicNameValuePair("szer", "52.321911"));
                    nameValuePairs.add(new BasicNameValuePair("dlug", "19.464111000000003"));
                    nameValuePairs.add(new BasicNameValuePair("opis", "jakis opis"));
                    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
     
                    // Execute HTTP Post Request
                    HttpResponse response = httpclient.execute(httppost);
                    HttpEntity responseEntity1 = response.getEntity();
        	    	String responseEntityString = EntityUtils.toString(responseEntity1);

    but insteed of submitting the request i got HTML of website as response, it looks like i dont try to make an entry but to read site content only. Any idea what i am doing wrong?


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: HTTP post to html servlet

    This thread has been cross posted here:

    http://www.java-forums.org/java-servlet/64205-http-post-html-servlet.html

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

    Java Programming Forums Cross Posting Rules

    The Problems With Cross Posting

    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Replies: 1
    Last Post: April 9th, 2012, 05:13 PM
  2. J2ME + Nokia S40 + HTTP Multiform POST to PHP website = 403 Forbidden
    By vozmen in forum Java ME (Mobile Edition)
    Replies: 2
    Last Post: January 12th, 2012, 04:30 AM
  3. Can't form a simple POST or GET http request. No data returns.
    By goodguy in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 29th, 2011, 05:04 AM
  4. Question About servlet and HTML
    By kurt-hardy in forum Java Theory & Questions
    Replies: 5
    Last Post: January 14th, 2011, 09:25 PM
  5. Http post to login to forum
    By durenir in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 14th, 2010, 11:03 AM