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">
    
    &lt;div class="form-group"&gt;
        &lt;textarea name="message" rows="4" class="form-control" placeholder="Сообщение"&gt;&lt;/textarea&gt;
    &lt;/div&gt;
    
    &lt;button class="btn btn-sm btn-primary"&gt;Отправить&lt;/button&gt;
    &lt;input type="hidden" name="MAX_FILE_SIZE" value="5242880"&gt;
    &lt;input type="file" name="attach" class="j-upload-file hidden"&gt;
    
    &lt;button class="btn btn-sm btn-default pull-right j-upload-file-btn"&gt;Прикрепить файл&lt;/button&gt;
    &lt;div class="pull-right j-file-name hidden"&gt;
        &lt;span class="j-name"&gt;&lt;/span&gt; &lt;a href="#" class="link-delete j-upload-delete"&gt;&lt;i class="fa fa-times"&gt;&lt;/i&gt;&lt;/a&gt;
    &lt;/div&gt;
    &lt;div class="clearfix"&gt;&lt;/div&gt;
    &lt;div class="help-block text-right mrgb0"&gt;Максимальный размер файла - 5 МБ&lt;/div&gt;
    &lt;input type="hidden" name="hash" value="4ee5104221f47408cd"&gt;&lt;/form&gt;
    



  • 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();
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2