Tabnine Logo
URLConnection.connect
Code IndexAdd Tabnine to your IDE (free)

How to use
connect
method
in
java.net.URLConnection

Best Java code snippets using java.net.URLConnection.connect (Showing top 20 results out of 8,208)

Refine searchRefine arrow

  • URL.openConnection
  • URL.<init>
  • URLConnection.getInputStream
  • HttpURLConnection.setRequestMethod
  • InputStream.close
  • URLConnection.setDoInput
origin: stackoverflow.com

 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);
origin: redisson/redisson

  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;
  }
}
origin: code4craft/tiny-spring

  @Override
  public InputStream getInputStream() throws IOException{
    URLConnection urlConnection = url.openConnection();
    urlConnection.connect();
    return urlConnection.getInputStream();
  }
}
origin: jenkinsci/jenkins

@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());
  }
}
origin: javax.xml.bind/jaxb-api

URLConnection con = url.openConnection();
con.setDoOutput(true);
con.setDoInput(false);
con.connect();
return new StreamResult(con.getOutputStream());
origin: stackoverflow.com

 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());
origin: stackoverflow.com

 URLConnection conn = url.openConnection();
conn.connect();

inputStream = conn.getInputStream();

bufferedInputStream = new BufferedInputStream(inputStream);

bmp = BitmapFactory.decodeStream(bufferedInputStream);
origin: stackoverflow.com

 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();
origin: stackoverflow.com

 URL url = new URL("http://server.com/file.mp3");
URLConnection urlConnection = url.openConnection();
urlConnection.connect();
int file_size = urlConnection.getContentLength();
origin: apache/hbase

 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);
  }
 }
}
origin: stackoverflow.com

 URL url = new URL("http://example.com");
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("GET");
connection.connect();

int code = connection.getResponseCode();
origin: stackoverflow.com

 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
}
origin: stackoverflow.com

 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;
  }
}
origin: stackoverflow.com

new URL("https://letsencrypt.org/").openConnection().connect();
origin: stackoverflow.com

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) {
origin: stackoverflow.com

 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;
}
origin: stackoverflow.com

 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();
origin: stackoverflow.com

 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 );
origin: stackoverflow.com

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();
origin: stackoverflow.com

 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();
java.netURLConnectionconnect

Javadoc

Opens a connection to the resource. This method will not reconnect to a resource after the initial connection has been closed.

Popular methods of URLConnection

  • getInputStream
    Returns an input stream that reads from this open connection. A SocketTimeoutException can be thrown
  • setUseCaches
    Sets the value of the useCaches field of thisURLConnection to the specified value. Some protocols do
  • setRequestProperty
    Sets the general request property. If a property with the key already exists, overwrite its value wi
  • getOutputStream
    Returns an output stream that writes to this connection.
  • getLastModified
    Returns the value of the last-modified header field. The result is the number of milliseconds since
  • setConnectTimeout
    Sets a specified timeout value, in milliseconds, to be used when opening a communications link to th
  • setDoOutput
    Sets the value of the doOutput field for thisURLConnection to the specified value. A URL connection
  • getContentLength
    Returns the value of the content-length header field.Note: #getContentLengthLong()should be preferre
  • setReadTimeout
    Sets the read timeout to a specified timeout, in milliseconds. A non-zero value specifies the timeou
  • getContentType
    Returns the value of the content-type header field.
  • getHeaderField
    Returns the value of the named header field. If called on a connection that sets the same header mul
  • setDoInput
    Sets the value of the doInput field for thisURLConnection to the specified value. A URL connection c
  • getHeaderField,
  • setDoInput,
  • addRequestProperty,
  • getURL,
  • getContentEncoding,
  • guessContentTypeFromName,
  • setDefaultUseCaches,
  • getFileNameMap,
  • getContent

Popular in Java

  • Reading from database using SQL prepared statement
  • getSharedPreferences (Context)
  • getExternalFilesDir (Context)
  • setScale (BigDecimal)
  • PrintWriter (java.io)
    Wraps either an existing OutputStream or an existing Writerand provides convenience methods for prin
  • Collectors (java.util.stream)
  • Filter (javax.servlet)
    A filter is an object that performs filtering tasks on either the request to a resource (a servlet o
  • JOptionPane (javax.swing)
  • Table (org.hibernate.mapping)
    A relational table
  • Logger (org.slf4j)
    The org.slf4j.Logger interface is the main user entry point of SLF4J API. It is expected that loggin
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now