Here you can find the source of post(String url, String postdata, String cookie)
public static HttpURLConnection post(String url, String postdata, String cookie)
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; public class Main { public static HttpURLConnection post(String url, String postdata, String cookie) {/*w ww. ja v a 2s . c om*/ HttpURLConnection pHuc = getConnection(url); pHuc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); pHuc.setRequestProperty("Origin", url.substring(0, url.indexOf("/"))); pHuc.setRequestProperty("Host", url.substring(0, url.indexOf("/"))); pHuc.setRequestProperty("Cookie", cookie); try { pHuc.setRequestMethod("POST"); pHuc.setDoOutput(true); pHuc.getOutputStream().write( postdata == null ? "".getBytes() : postdata.getBytes()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } return pHuc; } public static HttpURLConnection getConnection(String url) { try { return (HttpURLConnection) new URL( url.startsWith("http://") ? url : "http://" + url) .openConnection(); } catch (Exception e) { } return null; } }