Here you can find the source of sendPostRequest(String path, String params, String encoding)
public static InputStream sendPostRequest(String path, String params, String encoding) throws UnsupportedEncodingException, MalformedURLException, IOException, ProtocolException
//package com.java2s; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.ProtocolException; import java.net.URL; public class Main { public static InputStream sendPostRequest(String path, String params, String encoding) throws UnsupportedEncodingException, MalformedURLException, IOException, ProtocolException { byte[] data = params.getBytes(encoding); URL url = new URL(path); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); conn.setDoOutput(true);/*from www . ja v a2s . c o m*/ conn.setRequestProperty("Content-Type", "application/x-javascript; charset=" + encoding); conn.setRequestProperty("Content-Length", String.valueOf(data.length)); conn.setConnectTimeout(5 * 1000); OutputStream outStream = conn.getOutputStream(); outStream.write(data); outStream.flush(); outStream.close(); if (conn.getResponseCode() == 200) return conn.getInputStream(); return null; } }