Tabnine Logo
java.net
Code IndexAdd Tabnine to your IDE (free)

How to use java.net

Best Java code snippets using java.net (Showing top 20 results out of 140,229)

origin: stackoverflow.com

 // First set the default cookie manager.
CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL));

// All the following subsequent URLConnections will use the same cookie manager.
URLConnection connection = new URL(url).openConnection();
// ...

connection = new URL(url).openConnection();
// ...

connection = new URL(url).openConnection();
// ...
origin: stackoverflow.com

 URLConnection connection = new URL(url + "?" + query).openConnection();
connection.setRequestProperty("Accept-Charset", charset);
InputStream response = connection.getInputStream();
// ...
origin: stackoverflow.com

 HttpURLConnection httpConnection = (HttpURLConnection) new URL(url).openConnection();
httpConnection.setRequestMethod("POST");
// ...
origin: stackoverflow.com

 URLConnection connection = new URL(url).openConnection();
connection.setDoOutput(true); // Triggers POST.
connection.setRequestProperty("Accept-Charset", charset);
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=" + charset);

try (OutputStream output = connection.getOutputStream()) {
  output.write(query.getBytes(charset));
}

InputStream response = connection.getInputStream();
// ...
origin: stackoverflow.com

 String name = c.getString(str_url);
URL url_value = new URL(name);
ImageView profile = (ImageView)v.findViewById(R.id.vdo_icon);
if (profile != null) {
  Bitmap mIcon1 =
    BitmapFactory.decodeStream(url_value.openConnection().getInputStream());
  profile.setImageBitmap(mIcon1);
}
origin: stackoverflow.com

 InputStream response = new URL(url).openStream();
// ...
origin: stackoverflow.com

 // Gather all cookies on the first request.
URLConnection connection = new URL(url).openConnection();
List<String> cookies = connection.getHeaderFields().get("Set-Cookie");
// ...

// Then use the same cookies on all subsequent requests.
connection = new URL(url).openConnection();
for (String cookie : cookies) {
  connection.addRequestProperty("Cookie", cookie.split(";", 2)[0]);
}
// ...
origin: spring-projects/spring-framework

@Override
public URI getURI() {
  try {
    return this.connection.getURL().toURI();
  }
  catch (URISyntaxException ex) {
    throw new IllegalStateException("Could not get HttpURLConnection URI: " + ex.getMessage(), ex);
  }
}
origin: iluwatar/java-design-patterns

/**
 * Creates a new UDP logging client.
 *
 * @param clientName the name of the client to be sent in logging requests.
 * @param port the port on which client will send logging requests.
 * @throws UnknownHostException if localhost is unknown
 */
public UdpLoggingClient(String clientName, int port) throws UnknownHostException {
 this.clientName = clientName;
 this.remoteAddress = new InetSocketAddress(InetAddress.getLocalHost(), port);
}
origin: square/okhttp

public Proxy toProxyAddress() {
 before();
 InetSocketAddress address = new InetSocketAddress(inetSocketAddress.getAddress()
     .getCanonicalHostName(), getPort());
 return new Proxy(Proxy.Type.HTTP, address);
}
origin: square/okhttp

 private InetAddress getConnectToInetAddress(Proxy proxy, HttpUrl url) throws IOException {
  return proxy.type() != Proxy.Type.DIRECT
    ? ((InetSocketAddress) proxy.address()).getAddress()
    : InetAddress.getByName(url.host());
 }
}
origin: stackoverflow.com

 String url = "http://example.com";
String charset = "UTF-8";  // Or in Java 7 and later, use the constant: java.nio.charset.StandardCharsets.UTF_8.name()
String param1 = "value1";
String param2 = "value2";
// ...

String query = String.format("param1=%s&param2=%s", 
   URLEncoder.encode(param1, charset), 
   URLEncoder.encode(param2, charset));
origin: spring-projects/spring-framework

  @Override
  protected boolean isPortAvailable(int port) {
    try {
      DatagramSocket socket = new DatagramSocket(port, InetAddress.getByName("localhost"));
      socket.close();
      return true;
    }
    catch (Exception ex) {
      return false;
    }
  }
};
origin: stackoverflow.com

InputStream error = ((HttpURLConnection) connection).getErrorStream();
origin: square/okhttp

/**
 * Extracts the status line from the supplied Java API {@link java.net.HttpURLConnection}. As per
 * the spec, the status line is held as the header with the null key. Returns {@code null} if
 * there is no status line.
 */
private static String extractStatusLine(HttpURLConnection httpUrlConnection) {
 // Java specifies that this will be be response header with a null key.
 return httpUrlConnection.getHeaderField(null);
}
origin: square/okhttp

@Override protected IOException newTimeoutException(IOException cause) {
 SocketTimeoutException socketTimeoutException = new SocketTimeoutException("timeout");
 if (cause != null) {
  socketTimeoutException.initCause(cause);
 }
 return socketTimeoutException;
}
origin: square/okhttp

 @Override
 public void setDefaultUseCaches(boolean defaultUseCaches) {
  super.setDefaultUseCaches(defaultUseCaches);
 }
}
origin: spring-projects/spring-framework

@Override
public URI getURI() {
  try {
    return this.connection.getURL().toURI();
  }
  catch (URISyntaxException ex) {
    throw new IllegalStateException(
        "Could not get HttpURLConnection URI: " + ex.getMessage(), ex);
  }
}
origin: spring-projects/spring-framework

@Override
public URI getURI() {
  try {
    return this.connection.getURL().toURI();
  }
  catch (URISyntaxException ex) {
    throw new IllegalStateException("Could not get HttpURLConnection URI: " + ex.getMessage(), ex);
  }
}
origin: spring-projects/spring-framework

@Override
public URI getURI() {
  try {
    return this.connection.getURL().toURI();
  }
  catch (URISyntaxException ex) {
    throw new IllegalStateException("Could not get HttpURLConnection URI: " + ex.getMessage(), ex);
  }
}
java.net

Most used classes

  • URL
    A Uniform Resource Locator that identifies the location of an Internet resource as specified by RFC
  • URI
  • InetAddress
    This class represents an Internet Protocol (IP) address. An IP address is either a 32-bit or 128-bit
  • InetSocketAddress
  • URLEncoder
    This class is used to encode a string using the format required by application/x-www-form-urlencoded
  • HttpURLConnection,
  • Socket,
  • URLConnection,
  • URLClassLoader,
  • ServerSocket,
  • MalformedURLException,
  • URISyntaxException,
  • NetworkInterface,
  • UnknownHostException,
  • JarURLConnection,
  • DatagramSocket,
  • SocketException,
  • DatagramPacket,
  • Proxy
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