Jayyrus
Jayyrus

Reputation: 13061

How to submit array using Jsoup

I use Jsoup to post a form like:

Document doc = Jsoup.connect("http://www.example.com/post.php")
   .data("titolo", titolo)
   .data("prezzo", price)
   .data("comune", comune)
   .data("descrizione", descrizione)
   .post();
System.out.println(doc.text());

I need to get some links and i have to post it. How can i do it? Is it possible to post an array the same way I post text?

Thanks!!

Upvotes: 0

Views: 1119

Answers (2)

mysomic
mysomic

Reputation: 1567

Here's a little method that will "post" a form element using whatever input values you supply but leaving hidden field values and other pre-filled values intact

public Document submitForm(Element formElement, Map<String, String> data) throws IOException {
    String src = formElement.attr("action");
    Elements inputElements = formElement.select("input");
    for (Element inputElement : inputElements) {
        if (!data.containsKey(inputElement.attr("name"))) {
            data.put(inputElement.attr("name"), inputElement.val());
        }
    }
    Connection.Response response = Jsoup.connect(src).method(Connection.Method.POST).data(data).execute();
    return response.parse();
}

Upvotes: 0

J. Bruni
J. Bruni

Reputation: 20490

Have you tried something like this?

Document doc = Jsoup.connect("http://www.mySite.com/post.php")
   .data("titolo", titolo)
   .data("prezzo", price)
   .data("comune", comune)
   .data("descrizione", descrizione)
   .data("link[]", "http://example1.com")
   .data("link[]", "http://example2.com")
   .data("link[]", "http://example3.com")
   .post();
System.out.println(doc.text());

Upvotes: 2

Related Questions