Here you can find the source of downloadData(String url, String params)
public static byte[] downloadData(String url, String params) throws IOException
//package com.java2s; //License from project: Apache License import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; public class Main { public static byte[] downloadData(String url, String params) throws IOException { HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); connection.setRequestMethod("POST"); connection.setDoOutput(true);/*from w w w . j a v a 2s .c om*/ connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); OutputStream output = connection.getOutputStream(); output.write(params.getBytes()); output.close(); int code = connection.getResponseCode(); if (code == 200) { InputStream in = connection.getInputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len; while ((len = in.read(buffer)) != -1) { out.write(buffer, 0, len); } return out.toByteArray(); } throw new IOException("error"); } }