URL url = new URL(user_image_url); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setDoInput(true); conn.connect(); InputStream is = conn.getInputStream(); bmImg = BitmapFactory.decodeStream(is);
private static URLConnection fetchClass0(String host, int port, String filename) throws IOException { URL url; try { url = new URL("http", host, port, filename); } catch (MalformedURLException e) { // should never reache here. throw new IOException("invalid URL?"); } URLConnection con = url.openConnection(); con.connect(); return con; } }
@Override public InputStream getInputStream() throws IOException{ URLConnection urlConnection = url.openConnection(); urlConnection.connect(); return urlConnection.getInputStream(); } }
@RequirePOST public FormValidation doCheckUrl(@QueryParameter String value) { Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER); try { URLConnection conn = ProxyConfiguration.open(new URL(value)); conn.connect(); if (conn instanceof HttpURLConnection) { if (((HttpURLConnection) conn).getResponseCode() != HttpURLConnection.HTTP_OK) { return FormValidation.error(Messages.ZipExtractionInstaller_bad_connection()); } } return FormValidation.ok(); } catch (MalformedURLException x) { return FormValidation.error(Messages.ZipExtractionInstaller_malformed_url()); } catch (IOException x) { return FormValidation.error(x,Messages.ZipExtractionInstaller_could_not_connect()); } }
URLConnection con = url.openConnection(); con.setDoOutput(true); con.setDoInput(false); con.connect(); return new StreamResult(con.getOutputStream());
System.setProperty("http.keepAlive", "false"); HttpURLConnection conn = (HttpURLConnection) mURL.openConnection(); conn.setUseCaches(false); conn.setRequestProperty("User-Agent", useragent); conn.setConnectTimeout(30000); conn.setDoOutput(true); conn.setDoInput(true); consumer.sign(conn); conn.connect(); InputSource is = new InputSource(conn.getInputStream());
URLConnection conn = url.openConnection(); conn.connect(); inputStream = conn.getInputStream(); bufferedInputStream = new BufferedInputStream(inputStream); bmp = BitmapFactory.decodeStream(bufferedInputStream);
URL url = new URL("http://www.example.com/resource"); HttpURLConnection httpCon = (HttpURLConnection) url.openConnection(); httpCon.setDoOutput(true); httpCon.setRequestProperty( "Content-Type", "application/x-www-form-urlencoded" ); httpCon.setRequestMethod("DELETE"); httpCon.connect();
URL url = new URL("http://server.com/file.mp3"); URLConnection urlConnection = url.openConnection(); urlConnection.connect(); int file_size = urlConnection.getContentLength();
private String getUrlContent(URL u) throws IOException { java.net.URLConnection c = u.openConnection(); c.setConnectTimeout(2000); c.setReadTimeout(2000); c.connect(); try (InputStream in = c.getInputStream()) { return IOUtils.toString(in); } } }
URL url = new URL("http://example.com"); HttpURLConnection connection = (HttpURLConnection)url.openConnection(); connection.setRequestMethod("GET"); connection.connect(); int code = connection.getResponseCode();
try { URL url = new URL("http://www.yoursite.com/"); URLConnection conn = url.openConnection(); conn.connect(); } catch (MalformedURLException e) { // the URL is not in a valid form } catch (IOException e) { // the connection couldn't be established }
public static Bitmap getBitmapFromURL(String src) { try { URL url = new URL(src); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoInput(true); connection.connect(); InputStream input = connection.getInputStream(); Bitmap myBitmap = BitmapFactory.decodeStream(input); return myBitmap; } catch (IOException e) { // Log exception return null; } }
new URL("https://letsencrypt.org/").openConnection().connect();
HttpURLConnection connection = null; try { URL url = new URL(sUrl[0]); connection = (HttpURLConnection) url.openConnection(); connection.connect(); input = connection.getInputStream(); output = new FileOutputStream("/sdcard/file_name.extension"); input.close(); return null; output.close(); if (input != null) input.close(); } catch (IOException ignored) {
public static boolean hasActiveInternetConnection(Context context) { if (isNetworkAvailable(context)) { try { HttpURLConnection urlc = (HttpURLConnection) (new URL("http://www.google.com").openConnection()); urlc.setRequestProperty("User-Agent", "Test"); urlc.setRequestProperty("Connection", "close"); urlc.setConnectTimeout(1500); urlc.connect(); return (urlc.getResponseCode() == 200); } catch (IOException e) { Log.e(LOG_TAG, "Error checking internet connection", e); } } else { Log.d(LOG_TAG, "No network available!"); } return false; }
URLConnection con = new URL( url ).openConnection(); System.out.println( "orignal url: " + con.getURL() ); con.connect(); System.out.println( "connected url: " + con.getURL() ); InputStream is = con.getInputStream(); System.out.println( "redirected url: " + con.getURL() ); is.close();
HttpURLConnection con = (HttpURLConnection)(new URL( url ).openConnection()); con.setInstanceFollowRedirects( false ); con.connect(); int responseCode = con.getResponseCode(); System.out.println( responseCode ); String location = con.getHeaderField( "Location" ); System.out.println( location );
ResultReceiver receiver = (ResultReceiver) intent.getParcelableExtra("receiver"); try { URL url = new URL(urlToDownload); URLConnection connection = url.openConnection(); connection.connect(); InputStream input = new BufferedInputStream(connection.getInputStream()); OutputStream output = new FileOutputStream("/sdcard/BarcodeScanner-debug.apk"); input.close(); } catch (IOException e) { e.printStackTrace();
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("123.0.0.1", 8080)); URL url = new URL("http://www.yahoo.com"); HttpURLConnection uc = (HttpURLConnection)url.openConnection(proxy); uc.connect();