Here you can find the source of sendPOST(final String myurl, final String paramns)
public static String sendPOST(final String myurl, final String paramns) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.net.URL; public class Main { private static final String URL = "http://thiner.herokuapp.com/api/user"; public static String sendPOST(final String myurl, final String paramns) throws IOException { final URL url = new URL(myurl); final HttpURLConnection conn = (HttpURLConnection) url .openConnection();//ww w . java2 s . co m conn.setReadTimeout(10000); conn.setConnectTimeout(15000); conn.setRequestMethod("POST"); conn.setDoInput(true); conn.setDoOutput(true); final OutputStreamWriter osw = new OutputStreamWriter( conn.getOutputStream(), "UTF-8"); osw.write(paramns); osw.flush(); final BufferedReader br = new BufferedReader(new InputStreamReader( conn.getInputStream(), "UTF-8")); final StringBuffer contentAsString = new StringBuffer(); String line; while ((line = br.readLine()) != null) { contentAsString.append(line); } osw.close(); br.close(); return contentAsString.toString(); } }