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

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

Java 8 HttpURLConnection 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: 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: 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: 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: getResponseCode
232:	responseCode = String.format("%d", (connection != null) ? connection.getResponseCode() : 200); 
Full Snippet Info
7
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: 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: 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: 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: 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: 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: setRequestMethod
40:	post.setRequestMethod("POST"); //$NON-NLS-1$ 
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: setRequestMethod, getHeaderField, setConnectTimeout, setReadTimeout
227:	return this.connection.getHeaderField(name); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: setRequestMethod, setConnectTimeout, setDoInput, setDoOutput, setReadTimeout
116:	conn.setConnectTimeout(getTimeoutMillis()); 
117:	conn.setReadTimeout(getTimeoutMillis()); 
-
120:	conn.setRequestProperty("Accept-Encoding", "gzip"); 
-
123:	conn.setRequestMethod("POST"); 
124:	conn.setDoOutput(true); 
125:	conn.setDoInput(true); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getResponseCode, setRequestMethod, connect, setRequestProperty
181:	conn.setRequestProperty("Authorization", "Basic " + new String(authEncBytes)); 
-
184:	conn.setRequestMethod("DELETE"); 
185:	conn.connect(); 
186:	int responseCode = conn.getResponseCode(); 
Full Snippet Info
8
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: 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: setInstanceFollowRedirects, getHeaderField, setConnectTimeout, setReadTimeout, setRequestProperty
90:	connection.setRequestProperty("User-Agent", "http://jadn.com/carcast"); 
91:	connection.setConnectTimeout(30 * 1000); 
92:	connection.setReadTimeout(20 * 1000); 
-
95:	connection.setInstanceFollowRedirects(false); 
-
98:	String redirectLocation = connection.getHeaderField("Location"); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: disconnect, getContentEncoding, getResponseCode, getInputStream, setConnectTimeout
141:	myActiveConnection.disconnect(); 
-
238:	myActiveConnection.setRequestProperty("Accept-Encoding", "gzip, deflate"); 
-
240:	responseCode = myActiveConnection.getResponseCode(); 
-
260:	myActiveConnection.setConnectTimeout(TIMEOUT); 
-
262:	encoding = myActiveConnection.getContentEncoding(); 
-
264:	responseStream = myActiveConnection.getInputStream(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: disconnect, connect, getHeaderField, getInputStream, setRequestProperty
179:	getimagecloseconn.setRequestProperty("connection", "close"); 
-
181:	getimagecloseconn.connect(); 
182:	String cachecontrol = getimagecloseconn.getHeaderField("Cache-Control"); 
183:	InputStream isclose = getimagecloseconn.getInputStream(); 
-
185:	getimagecloseconn.disconnect(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: setInstanceFollowRedirects, getInputStream, setConnectTimeout, setReadTimeout
368:	Util.setIgnoreSSLError(conn); 
-
370:	conn.setConnectTimeout(30000); 
371:	conn.setReadTimeout(30000); 
372:	conn.setInstanceFollowRedirects(true); 
373:	final InputStream is = conn.getInputStream(); 
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: setDoInput
73:	conn.setDoInput(true); 
74:	return processResponse(conn); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getHeaderField, setConnectTimeout, setReadTimeout
157:	connection.setConnectTimeout(15000); 
158:	connection.setReadTimeout(30000); 
159:	contentLength = connection.getHeaderField("content-length"); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getResponseCode, setInstanceFollowRedirects, setRequestMethod, connect, getInputStream
272:	httpConn.setAllowUserInteraction(false); 
273:	httpConn.setInstanceFollowRedirects(true); 
274:	httpConn.setRequestMethod("GET"); 
275:	httpConn.connect(); 
-
277:	response = httpConn.getResponseCode(); 
-
280:	in = httpConn.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: 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: setDoInput
73:	conn.setDoInput(true); 
74:	return processResponse(conn); 
Full Snippet Info
7
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: 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, setDoInput
290:	connection.setDoInput(true); 
291:	connection.connect(); 
292:	InputStream input = connection.getInputStream(); 
Full Snippet Info
8
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: getResponseCode, setRequestMethod, addRequestProperty, connect, getInputStream
93:	connection.setRequestMethod("GET"); 
94:	connection.setRequestProperty("Accept", "text/plain"); 
95:	connection.setRequestProperty("hello", "world"); 
96:	connection.addRequestProperty("hello", "universe"); 
-
98:	connection.setDoOutput(false); 
99:	connection.connect(); 
-
101:	assertThat(connection.getResponseCode(), equalTo(200)); 
102:	assertThat(ReaderWriter.readFromAsString(new InputStreamReader(connection.getInputStream())), 
Full Snippet Info
8
CodeRank
Related Java 8 HttpURLConnection Questions & Answers:
Other Java 8 HttpURLConnection Examples
92:	            CommonUtilities.displayMessage(context, message);
93:	        } catch (IOException e) {
94:	            // At this point the device is unregistered from GCM, but still
95:	            // registered in the server.
96:	            // We could try to unregister again, but it is not necessary:
-
95:	            // registered in the server.
96:	            // We could try to unregister again, but it is not necessary:
97:	            // if the server tries to send a message to the device, it will get
98:	            // a "NotRegistered" error message and should unregister the device.
99:	            String message = context.getString(R.string.server_unregister_error,

Read More

66:	            Bitmap bitmap=null;
67:	            URL imageUrl = new URL(url);
68:	            HttpURLConnection conn = (HttpURLConnection)imageUrl.openConnection();
69:	            conn.setConnectTimeout(30000);
70:	            conn.setReadTimeout(30000);
-
66:	            Bitmap bitmap=null;
67:	            URL imageUrl = new URL(url);
68:	            HttpURLConnection conn = (HttpURLConnection)imageUrl.openConnection();
69:	            conn.setConnectTimeout(30000);
70:	            conn.setReadTimeout(30000);

Read More

65:	            URL imageUrl = new URL(url);
66:	            HttpURLConnection conn = (HttpURLConnection)imageUrl.openConnection();
67:	            conn.setConnectTimeout(30000);
68:	            conn.setReadTimeout(30000);
69:	            conn.setInstanceFollowRedirects(true);
-
65:	            URL imageUrl = new URL(url);
66:	            HttpURLConnection conn = (HttpURLConnection)imageUrl.openConnection();
67:	            conn.setConnectTimeout(30000);
68:	            conn.setReadTimeout(30000);
69:	            conn.setInstanceFollowRedirects(true);

Read More

See Code Examples for Java 8 HttpURLConnection Methods: