-1

i need to parse this page (http://www.poste.it/online/dovequando/home.do) after obvusly input (name="mpcode"). This is my code. How can i do?

public static void poste(String trackingCode) {

    try {
        HttpURLConnection httpcon = (HttpURLConnection) ((new URL(
                "http://www.poste.it/online/dovequando/ricerca.do")
                .openConnection()));
        httpcon.setDoOutput(true);
        httpcon.setRequestMethod("POST");
        httpcon.connect();
        byte[] outputBytes = "{'mpcode': trackingCode}"
                .getBytes("UTF-8");
        OutputStream os = httpcon.getOutputStream();
        os.write(outputBytes);
        os.close();
    } catch (IOException e) {
    }
}

1 Answers1

0

You can use java.util.Scanner for read the stream. e.g.:

Scanner sc = new Scanner(httpcon.getInputStream());
sc.useDelimiter("\\A");

String content = sc.next();
Paul Vargas
  • 38,878
  • 15
  • 91
  • 139
  • You may want to see http://stackoverflow.com/questions/2793150/using-java-net-urlconnection-to-fire-and-handle-http-requests – Paul Vargas Jan 30 '15 at 00:52