Java URL Connection addHeaders(URLConnection conn)

Here you can find the source of addHeaders(URLConnection conn)

Description

adds headers to the url to make it look less like a bot

License

Open Source License

Parameter

Parameter Description
conn the connection to modify

Declaration

public static void addHeaders(URLConnection conn) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.IOException;

import java.net.URLConnection;

public class Main {
    public static String userAgent;

    /**//from   w ww .java  2  s.co  m
     * adds headers to the url to make it look less like a bot
     * @param conn the connection to modify
     */
    public static void addHeaders(URLConnection conn) throws IOException {
        conn.addRequestProperty("User-Agent", userAgent);
        conn.addRequestProperty("Accept-Language", "en-US,en;q=0.5");
        conn.addRequestProperty("Accept-Encoding", "gzip,deflate");
        conn.addRequestProperty("DNT", "1");
    }
}

Related

  1. addHeaders(Map headers, URLConnection c)
  2. addProperty(URLConnection connection)
  3. byteArrayToURL(final byte[] bytes)
  4. closeURLClassLoader(URLClassLoader clazzLdr)
  5. createImgUrlConnection(String url)