Post request for data in the form of the Jsoup Library
-
Objectivesend the data to the site, namely, send the message to the user.
Example: editing, followed by a switch to the user ' s data pass page:
Connection.Response res = Jsoup.connect("http://адрес/user/login") .data("email", edt_email.getText().toString()) .data("pass", edt_pass.getText().toString()) .method(Method.POST) .execute(); Document doc = res.parse(); sessionId = res.cookie("bffssu"); Log.i("idSession", sessionId.toString()); Document doc2 = Jsoup.connect("http://адрес") .userAgent("Mozzila") .cookie("bffssu", sessionId) .get(); el_get_trulyalya = doc2.select("div.j-list");
Next, we need to send a message to the user. Form of communication to html:
<form class="i-imailDialog-form form bff_ajax_iframe_inited" method="POST" action="http://адрес/user/messages?i=vadumo" id="j-my-chat-form" enctype="multipart/form-data" target="bff_ajax_iframe226"> <input type="hidden" name="act" value="send"> <input type="hidden" name="i" value="vadumo">
<div class="form-group"> <textarea name="message" rows="4" class="form-control" placeholder="Сообщение"></textarea> </div> <button class="btn btn-sm btn-primary">Отправить</button> <input type="hidden" name="MAX_FILE_SIZE" value="5242880"> <input type="file" name="attach" class="j-upload-file hidden"> <button class="btn btn-sm btn-default pull-right j-upload-file-btn">Прикрепить файл</button> <div class="pull-right j-file-name hidden"> <span class="j-name"></span> <a href="#" class="link-delete j-upload-delete"><i class="fa fa-times"></i></a> </div> <div class="clearfix"></div> <div class="help-block text-right mrgb0">Максимальный размер файла - 5 МБ</div> <input type="hidden" name="hash" value="4ee5104221f47408cd"></form>
-
Perhaps the server side is clearly expecting a multipart. Require in this mode without sending the file itself, as follows:
Document doc = Jsoup.connect("http://адрес/user/messages?i=vadumo") .header("Content-Type", "multipart/form-data") .userAgent("Mozilla") .data("message","Test") .post();