Best code examples for Java 8 URLConnection class (java.net.URLConnection)

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 URLConnection class.
You can now enable Codota on your own code to easily search and navigate your Java codebase.

Java 8 URLConnection examples from Open Source projects
This code example shows how to use the following methods: setRequestMethod, setRequestProperty, setSSLSocketFactory
150:	connection.setSSLSocketFactory(context.getSocketFactory()); 
151:	connection.setRequestMethod(method); 
152:	connection.setRequestProperty("Content-Type", "application/json"); 
-
156:	connection.setRequestProperty("Authorization", getAuthorizationHeader()); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: connect, getInputStream, setConnectTimeout
145:	connection.setConnectTimeout(5000); 
146:	connection.connect(); 
-
153:	inputStream = connection.getInputStream(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: disconnect, getResponseCode, setChunkedStreamingMode, setRequestMethod, getOutputStream
40:	connection.setRequestMethod("PUT"); 
41:	connection.setDoOutput(true); 
42:	connection.setChunkedStreamingMode(fileContents.length); 
43:	OutputStream os = connection.getOutputStream(); 
-
46:	assertTrue(isSuccessfulCode(connection.getResponseCode())); 
47:	connection.disconnect(); 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods: getContentLength, getContentType, getInputStream
55:	is = uc.getInputStream(); 
-
57:	ParsedContentType pct = new ParsedContentType(uc.getContentType()); 
-
64:	capacityHint = uc.getContentLength(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: disconnect, getResponseCode, connect, setRequestProperty
98:	connection.setRequestProperty("Accept", contentTypes); 
99:	connection.setRequestProperty("Accept-Charset", "utf-8,*"); 
100:	connection.setRequestProperty("User-Agent", "ZXing (Android)"); 
-
103:	connection.connect(); 
-
115:	responseCode = connection.getResponseCode(); 
-
127:	connection.disconnect(); 
Full Snippet Info
10
CodeRank
This code example shows how to use the following methods: connect, getHeaderField, getInputStream, setRequestProperty
30:	public String errors() 
31:	{ 
-
45:	connection.setRequestProperty("User-Agent", "Nagare"); 
46:	connection.connect(); 
-
48:	m_shoutcast_file.download(this, connection.getInputStream()); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: connect, getInputStream
235:	conn.connect(); 
236:	InputStream stream = conn.getInputStream(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getResponseCode, connect
49:	conn.connect(); 
50:	Assert.assertEquals(HttpURLConnection.HTTP_OK, conn.getResponseCode()); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: setDoInput
76:	conn.setDoInput(true); 
77:	return processResponse(conn); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getResponseCode, getInputStream
37:	super(connection); 
38:	if (connection.getResponseCode() < 400) { 
-
45:	xr.parse(new InputSource(connection.getInputStream())); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getResponseCode, getResponseMessage, setAllowUserInteraction, setConnectTimeout, setReadTimeout
128:	conn.setConnectTimeout(timeout); 
129:	conn.setReadTimeout(timeout); 
130:	conn.setAllowUserInteraction(false); 
131:	if(conn.getResponseCode() != HttpURLConnection.HTTP_OK) { 
-
133:	+ conn.getResponseCode() + " and message \"" + conn.getResponseMessage() 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: setRequestMethod, getOutputStream, setDoOutput, setRequestProperty
40:	urlConnection.setRequestMethod("POST"); 
41:	urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); 
42:	urlConnection.setDoOutput(true); 
43:	urlConnection.getOutputStream().write(body.getBytes(Charset.forName("UTF8"))); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getInputStream, setConnectTimeout, setReadTimeout
16:	connection.setConnectTimeout(5000); 
17:	connection.setReadTimeout(5000); 
18:	reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: connect, getInputStream, setDoInput
269:	connection.setDoInput(true); 
270:	connection.connect(); 
271:	InputStream input = connection.getInputStream(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getOutputStream, setDoOutput, setRequestProperty
136:	urlConnection.setDoOutput(true); 
-
143:	urlConnection.setRequestProperty("Content-Type", contentType); 
-
146:	urlConnection.setRequestProperty( 
-
151:	urlConnection.getOutputStream(), 8192); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: setRequestMethod, connect, getInputStream, setConnectTimeout, setDoInput
184:	conn.connect(); 
-
186:	InputStream stream = conn.getInputStream(); 
-
201:	conn.setReadTimeout(10000 /* milliseconds */); 
202:	conn.setConnectTimeout(15000 /* milliseconds */); 
203:	conn.setDoInput(true); 
204:	conn.setRequestMethod("GET"); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: setRequestMethod, setDoInput, setDoOutput, setRequestProperty, setUseCaches
55:	connection.setRequestMethod("POST"); 
56:	connection.setDoInput(true); 
57:	connection.setDoOutput(true); 
58:	connection.setUseCaches(false); 
59:	connection.setRequestProperty(HTTP_FIELD_CONTENT_TYPE, CONTENT_TYPE_URLENCODED); 
60:	connection.setRequestProperty(HTTP_FIELD_CONTENT_LENGTH, String.valueOf(length)); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getInputStream, getOutputStream, setDoOutput
29:	conn.setDoOutput(true); 
30:	OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream()); 
-
34:	Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(conn.getInputStream()); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: connect, getInputStream, setConnectTimeout, setReadTimeout
35:	conn.setConnectTimeout(1000); 
36:	conn.setReadTimeout(1000); 
37:	conn.connect(); 
38:	return DefaultSaxParser.parse(conn.getInputStream()); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getResponseCode, setInstanceFollowRedirects, setRequestMethod, connect, getInputStream
292:	httpConn.setAllowUserInteraction(false); 
293:	httpConn.setInstanceFollowRedirects(true); 
294:	httpConn.setRequestMethod("GET"); 
295:	httpConn.connect(); 
-
297:	response = httpConn.getResponseCode(); 
-
300:	in = httpConn.getInputStream(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: disconnect, getResponseCode, connect
176:	connection.connect(); 
177:	Assert.assertEquals(200, connection.getResponseCode()); 
-
179:	connection.disconnect(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: connect, getInputStream
121:	conn.connect(); 
-
123:	is = new BufferedInputStream(conn.getInputStream()); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getConnectTimeout, getDoInput, getDoOutput, getReadTimeout, getURL
64:	assertEquals(30000, urlConnection.getConnectTimeout()); 
65:	assertEquals(30000, urlConnection.getReadTimeout()); 
66:	assertFalse(urlConnection.getUseCaches()); 
67:	assertTrue(urlConnection.getDoInput()); 
68:	assertFalse(urlConnection.getDoOutput()); 
69:	assertEquals(new URL(connectionProcessor.getServerURL() + "/i?" + eventData), urlConnection.getURL()); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: connect, getInputStream, setDoInput
84:	conn.setDoInput(true); 
85:	conn.connect(); 
86:	InputStream is = conn.getInputStream(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: setInstanceFollowRedirects, getInputStream, setConnectTimeout, setReadTimeout
302:	Util.setIgnoreSSLError(conn); 
-
304:	conn.setConnectTimeout(30000); 
305:	conn.setReadTimeout(30000); 
306:	conn.setInstanceFollowRedirects(true); 
307:	final InputStream is = conn.getInputStream(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getInputStream, setConnectTimeout, setReadTimeout
83:	conn.setConnectTimeout(connectionTimeout); 
84:	conn.setReadTimeout(readTimeout); 
85:	return conn.getInputStream(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: connect, getContentLength, getHeaderField, getHeaderFieldDate, getInputStream
132:	c.setDoOutput(false); 
133:	c.setAllowUserInteraction(false); 
-
139:	c.connect(); 
-
141:	c.getInputStream().close(); 
-
146:	modificationDate = c.getHeaderFieldDate("last-modified", -1); 
-
158:	contentLength = new Long(c.getContentLength()); 
159:	contentType = c.getHeaderField("content-type"); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: connect, getContentEncoding, getContentLength, getContentType, getInputStream
32:	conn.connect(); 
-
34:	contentLength = conn.getContentLength(); 
35:	contentType = findContentType(conn.getContentType(), url); 
36:	contentEncoding = conn.getContentEncoding(); 
37:	lastModified = conn.getLastModified(); 
-
41:	conn.getInputStream().close(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: connect, getContentLength, getHeaderField, getHeaderFieldDate, getInputStream
132:	c.setDoOutput(false); 
133:	c.setAllowUserInteraction(false); 
-
139:	c.connect(); 
-
141:	c.getInputStream().close(); 
-
146:	modificationDate = c.getHeaderFieldDate("last-modified", -1); 
-
158:	contentLength = new Long(c.getContentLength()); 
159:	contentType = c.getHeaderField("content-type"); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getInputStream, setSSLSocketFactory
111:	conn.setSSLSocketFactory(clientSslFactory.createSSLSocketFactory()); 
112:	InputStream in = conn.getInputStream(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: addRequestProperty, getContentEncoding, getInputStream
67:	con.addRequestProperty("Accept", accept); 
68:	con.addRequestProperty("Accept-Charset", encoding); 
69:	String enc = con.getContentEncoding(); 
-
73:	getReceiver().process(new InputStreamReader(con.getInputStream(), enc)); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: connect, getInputStream
211:	connection.connect(); 
-
213:	try (Reader in = new BufferedReader(new InputStreamReader(connection.getInputStream(), UTF8))) { 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getResponseCode, setRequestMethod, connect, getOutputStream, setDoOutput
77:	connection.setRequestMethod("POST"); 
78:	connection.setRequestProperty("Accept", "text/plain"); 
79:	connection.setRequestProperty("Content-Type", "application/json, app/json"); 
-
81:	connection.setDoOutput(true); 
82:	connection.connect(); 
-
84:	final OutputStream outputStream = connection.getOutputStream(); 
-
89:	assertEquals(400, connection.getResponseCode()); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: connect, getInputStream, setDoInput
95:	connection.setDoInput(true); 
96:	connection.connect(); 
97:	InputStream input = connection.getInputStream(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: disconnect, getResponseCode, getResponseMessage, setRequestMethod, connect
82:	connection.setRequestMethod("GET"); 
-
84:	connection.connect(); 
-
86:	final int statusCode = connection.getResponseCode(); 
87:	final String statusMessage = connection.getResponseMessage(); 
-
89:	connection.disconnect(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getInputStream, getHostnameVerifier, setSSLSocketFactory
75:	urlConnection.setSSLSocketFactory(sslContext.getSocketFactory()); 
76:	Log.i(TAG,"hostnameverifier is: " + urlConnection.getHostnameVerifier().getClass().getName()); 
-
78:	return urlConnection.getInputStream(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: connect, getInputStream, setDoInput
81:	c.setDoInput( true ); 
82:	c.connect(); 
83:	InputStream is = c.getInputStream(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: setRequestMethod, setDoInput, setDoOutput, setRequestProperty
144:	connection.setDoInput(true); 
145:	connection.setDoOutput(true); 
146:	connection.setRequestMethod(POST_REQUEST_METHOD); 
147:	connection.setRequestProperty("Content-Type", contentType); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: setRequestMethod, getInputStream, setRequestProperty
60:	conn.setRequestProperty("User-Agent", useragent); 
-
266:	conn.setRequestMethod("GET"); 
267:	return BitmapFactory.decodeStream(conn.getInputStream()); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: setRequestMethod, setConnectTimeout, setDoOutput, setReadTimeout, setRequestProperty
14:	connection.setConnectTimeout(0); 
15:	connection.setReadTimeout(0); 
16:	connection.setRequestMethod("GET"); 
-
18:	connection.setRequestProperty("Authorization", authValue); 
-
20:	connection.setDoOutput(true); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getInputStream, setConnectTimeout, setReadTimeout, setUseCaches
78:	connection.setUseCaches(false); 
-
82:	connection.setConnectTimeout(timeout); 
83:	connection.setReadTimeout(timeout); 
-
85:	return new BufferedInputStream(connection.getInputStream()); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getResponseCode, connect, getInputStream, setDoInput
57:	conn.setDoInput(true); 
58:	conn.connect(); 
-
61:	if (aURL == null || (conn != null && conn.getResponseCode() != 404)) { 
62:	is = conn.getInputStream(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: connect, getInputStream, setConnectTimeout
145:	connection.setConnectTimeout(5000); 
146:	connection.connect(); 
-
153:	inputStream = connection.getInputStream(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: setRequestMethod, getHeaderField, setDoInput
170:	conn.setDoInput(false); 
171:	conn.setRequestMethod("HEAD"); 
172:	return conn.getHeaderField("Content-Type"); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: addRequestProperty, getOutputStream, setDoOutput
40:	con.setDoOutput(true); 
41:	con.addRequestProperty("Content-Type", mime); 
42:	con.addRequestProperty("Content-Length", String.valueOf(content.length)); 
43:	OutputStream os = con.getOutputStream(); 
Full Snippet Info
7
CodeRank
Related Java 8 URLConnection Questions & Answers:
Other Java 8 URLConnection Examples
21:		            URL url = new URL(f_url[0]);
22:		            URLConnection conection = url.openConnection();
23:		            conection.connect();
24:		            // getting file length
25:		            int lenghtOfFile = conection.getContentLength();

Read More

98:		            URL url = new URL(f_url[0]);
99:		            URLConnection conection = url.openConnection();
100:		            conection.connect();
101:		            // this will be useful so that you can show a tipical 0-100% progress bar
102:		            int lenghtOfFile = conection.getContentLength();

Read More

See Code Examples for Java 8 URLConnection Methods: