Results 1 to 3 of 3
Like Tree2Likes
  • 2 Post By JosAH

Thread: HTTP post to html servlet

  1. #1
    Mith is offline Member
    Join Date
    Oct 2012
    Posts
    1
    Rep Power
    0

    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
    XML Code:
    url is:someblog.com/blog.jsp?action=new
    html of a servlet that is responsible to manually add entries:
    XML 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:

    Java Code:
    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?
    Last edited by Mith; 10-23-2012 at 05:45 PM.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,143
    Rep Power
    10

    Default Re: HTTP post to html servlet

    How to Ask Questions the Smart Way
    Static Void Games - GameDev tutorials, free Java and JavaScript hosting!
    Static Void Games forum - Come say hello!

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,051
    Blog Entries
    7
    Rep Power
    23

    Default Re: HTTP post to html servlet

    @Mith: I received a notification telling us that KevinWorkman's reply shouldn't be of any help; it is very helpful though: it warns us not to spend too much time on your question because it might be answered already elsewhere.

    kind regards,

    Jos
    KevinWorkman and DarrylBurke like this.
    The only person who got everything done by Friday was Robinson Crusoe.

Similar Threads

  1. HTTP Post
    By mwr1976 in forum Networking
    Replies: 2
    Last Post: 02-22-2012, 04:33 PM
  2. applet and jar http post help
    By jobud9 in forum New To Java
    Replies: 2
    Last Post: 12-20-2011, 12:53 AM
  3. http post
    By cino in forum Advanced Java
    Replies: 8
    Last Post: 06-13-2011, 04:08 PM
  4. HTTP POST over sockets
    By DC200 in forum Networking
    Replies: 2
    Last Post: 09-19-2010, 03:00 PM
  5. HTTP Post
    By erics44 in forum New To Java
    Replies: 0
    Last Post: 03-22-2010, 02:01 PM

Posting Permissions

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