How to send text via forms using JSoup

advertisements

I'd like to submit some text into this form using JSoup. How would I go about doing this?

<form id="quickpostform" action="" method="post" style="display: block; text-align: center; ">
<input type="hidden" name="action" value="reply"/>
<input type="hidden" name="auth" value="54a9871a63a1c285879a5327faf3d8d2"/>
<input type="hidden" name="thread" value="135454"/>
<div id="quickreplytext">
<textarea id="quickpost" style="width: 95%; " tabindex="1" onkeyup="resize('quickpost');" name="body" cols="90" rows="8"/>
<br/>
</div>


Take a look at the jsoup.connect method and the Connection interface.

Once you have the text you want to submit ready to go, you can post it to a URL as a form submission.

E.g.:

Document doc = Jsoup.connect(url)
    .data("action", "reply")
    .data("auth", "54a9871a63a1c285879a5327faf3d8d2")
    .data("thread", "135454")
    .data("quickreplytext", replyText)
    .post();

The returned doc object will be the result page of the post.