Java HTTP Header getConnection(URL url, String method, Map header, String ctype)

Here you can find the source of getConnection(URL url, String method, Map header, String ctype)

Description

get Connection

License

Apache License

Declaration

private static HttpURLConnection getConnection(URL url, String method, Map<String, String> header, String ctype)
            throws IOException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;

import java.util.Map;
import java.util.Map.Entry;

public class Main {
    private static HttpURLConnection getConnection(URL url, String method, Map<String, String> header, String ctype)
            throws IOException {
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setUseCaches(false);/*  w ww.  ja va 2s .  c  o m*/
        conn.setDoInput(true);
        conn.setDoOutput(true);
        conn.setRequestMethod(method);
        //    conn.setRequestProperty("Accept", "text/xml,text/javascript");
        //    conn.setRequestProperty("User-Agent", "iLegendSoft-Test-Client");
        conn.setRequestProperty("Content-Type", "application/json");
        if (header != null && header.size() > 0)
            for (Entry<String, String> entry : header.entrySet()) {
                conn.setRequestProperty(entry.getKey(), entry.getValue());
            }
        return conn;
    }
}

Related

  1. dumpHeaders(HttpURLConnection conn)
  2. dumpHeaders(HttpURLConnection conn, PrintStream out)
  3. dumpHttpHeaders(HttpURLConnection conn, java.io.PrintStream out)
  4. fillHeaders(HttpURLConnection urlConnection, Map headers)
  5. GET_Stream(String url, HashMap headers)
  6. getFromUrl(Map headerMap, URL loc, Proxy proxy)
  7. getHeaderField(final URL url, final String name)
  8. getHttpResponseHeader(HttpURLConnection http)
  9. getIntFromHeader(HttpURLConnection connection, String headerName)