Search code examples
androidformsjsoupresponse

Can't get response from Jsoup on sended form


i'm trying to send a form to a site and get the response in an Android application. Thing is, the response is just empty html file (just the tags html, head and body, open and closed), nothing more. Here is my code:

Connection.Response loginForm = Jsoup.connect("http://m.correios.com.br/movel/calculaPrecos.do").method(Connection.Method.GET)
                        .userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.0 Safari/537.36")
                        .execute();
                Document document = Jsoup
                        .connect("http://m.correios.com.br/movel/precos.do")
                        .userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.0 Safari/537.36")
                        .data("servico", "40215")
                        .data("cepOrigem", "97010-200")
                        .data("cepDestino", "97015-259")
                        .data("peso", "1")
                        .data("formato", "1")
                        .data("comprimento", "23")
                        .data("altura", "23")
                        .data("largura", "23")
                        .data("diametro", "")
                        .data("maoPropria", "N")
                        .data("valorDeclarado", "")
                        .data("avisoRecebimento", "N")
                        .data("metodo", "calcular")
                        .cookies(loginForm.cookies())
                        .followRedirects(true)
                        .method(Connection.Method.POST)
                        .post();
                System.out.println("Output>>> "+document.toString());

the form which i got from chrome


Solution

  • You are using wrong URL for the POST request. You are using http://m.correios.com.br/movel/precos.do but it should be http://m.correios.com.br/movel/calculaPrecos.do - same as for the GET request (notice the part before the last dot).