Here you can find the source of getHttpURLConnection(String postUrl)
private static HttpURLConnection getHttpURLConnection(String postUrl) throws IOException
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; public class Main { private static HttpURLConnection getHttpURLConnection(String postUrl) throws IOException { URL url = new URL(postUrl); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoInput(true);//from www . j ava2s . c o m connection.setDoOutput(true); connection.setRequestMethod("POST"); connection.setUseCaches(false); connection.setInstanceFollowRedirects(true); connection.setRequestProperty("Content-Type", "application/json"); connection.connect(); return connection; } }