Java HttpURLConnection Create getHttpURLConnection(String postUrl)

Here you can find the source of getHttpURLConnection(String postUrl)

Description

get Http URL Connection

License

Apache License

Declaration

private static HttpURLConnection getHttpURLConnection(String postUrl) throws IOException 

Method Source Code

//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;
    }
}

Related

  1. getHttpConnection(String urlStr, String charSet, Map props)
  2. getHTTPConnection(String urlString)
  3. getHttpConnection(URL url)
  4. getHttpConnection(URL url, int expectedResponseCode, int connectionTimeout)
  5. getHttpURLConnection(@Nonnull String urlStr)
  6. getHttpURLConnection(String strUrl)
  7. getHttpURLConnection(String uri, String soapAction, boolean soap12)
  8. getHttpUrlConnection(String url)
  9. getHttpURLConnection(String urlAsString)