Code example for HttpURLConnection

Methods: addRequestProperty, setConnectTimeout

0
		return url.getHost().toLowerCase().contains("runescape") ? HTTP_USERAGENT_FAKE : HTTP_USERAGENT_REAL;
	} 
 
	public static HttpURLConnection getHttpConnection(final URL url) throws Exception {
		final HttpURLConnection con = (HttpURLConnection) url.openConnection();
		con.addRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
		con.addRequestProperty("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
		con.addRequestProperty("Accept-Encoding", "gzip, deflate");
		con.addRequestProperty("Accept-Language", "en-us,en;q=0.5");
		con.addRequestProperty("Host", url.getHost());
		con.addRequestProperty("User-Agent", getHttpUserAgent(url));
		con.setConnectTimeout(10000);
		return con;
	} 
 
	public static URLConnection getURLConnection(final URL url) throws Exception {
		final URLConnection con = url.openConnection();
		con.addRequestProperty("Protocol", "HTTP/1.1");
		con.addRequestProperty("Connection", "keep-alive");
		con.addRequestProperty("Keep-Alive", "200");
		con.addRequestProperty("User-Agent", getHttpUserAgent(url));