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

How to use
getHeaderField
method
in
java.net.URLConnection

Best Java code snippets using java.net.URLConnection.getHeaderField (Showing top 20 results out of 5,085)

Refine searchRefine arrow

  • URL.openConnection
  • URL.<init>
  • HttpURLConnection.getResponseCode
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

 URL url = new URL(url);
HttpURLConnection ucon = (HttpURLConnection) url.openConnection();
ucon.setInstanceFollowRedirects(false);
URL secondURL = new URL(ucon.getHeaderField("Location"));
URLConnection conn = secondURL.openConnection();
origin: apache/incubator-druid

@JsonCreator
public HttpFirehoseFactory(
  @JsonProperty("uris") List<URI> uris,
  @JsonProperty("maxCacheCapacityBytes") Long maxCacheCapacityBytes,
  @JsonProperty("maxFetchCapacityBytes") Long maxFetchCapacityBytes,
  @JsonProperty("prefetchTriggerBytes") Long prefetchTriggerBytes,
  @JsonProperty("fetchTimeout") Long fetchTimeout,
  @JsonProperty("maxFetchRetry") Integer maxFetchRetry
) throws IOException
{
 super(maxCacheCapacityBytes, maxFetchCapacityBytes, prefetchTriggerBytes, fetchTimeout, maxFetchRetry);
 this.uris = uris;
 Preconditions.checkArgument(uris.size() > 0, "Empty URIs");
 final URLConnection connection = uris.get(0).toURL().openConnection();
 final String acceptRanges = connection.getHeaderField(HttpHeaders.ACCEPT_RANGES);
 this.supportContentRange = acceptRanges != null && "bytes".equalsIgnoreCase(acceptRanges);
}
origin: stackoverflow.com

 URL url = new URL("JSPURL");
URLConnection conn = url.openConnection();
for (int i = 0;; i++) {
 String headerName = conn.getHeaderFieldKey(i);
 String headerValue = conn.getHeaderField(i);
 System.out.println(headerName + "===");
 System.out.println(headerValue);
 if (headerName == null && headerValue == null) {
  break;
 }
}
origin: stackoverflow.com

 HttpURLConnection conn = (HttpURLConnection) feedUrl.openConnection();
int responseCode = conn.getResponseCode();
if( responseCode == 307 ){
  String location = conn.getHeaderField("location");
  feedUrl = new URL(location);
  conn = (HttpURLConnection) this.feedUrl.openConnection();
}
origin: neo4j-contrib/neo4j-apoc-procedures

private static String handleRedirect(URLConnection con, String url) throws IOException {
  if (!(con instanceof HttpURLConnection)) return url;
  if (!isRedirect(((HttpURLConnection)con).getResponseCode())) return url;
  return con.getHeaderField("Location");
}
origin: jenkinsci/jenkins

/**
 * If the server advertises CLI endpoint, returns its location.
 * @deprecated Specific to {@link Mode#REMOTING}.
 */
@Deprecated
protected CliPort getCliTcpPort(URL url) throws IOException {
  if (url.getHost()==null || url.getHost().length()==0) {
    throw new IOException("Invalid URL: "+url);
  }
  URLConnection head = url.openConnection();
  try {
    head.connect();
  } catch (IOException e) {
    throw (IOException)new IOException("Failed to connect to "+url).initCause(e);
  }
  String h = head.getHeaderField("X-Jenkins-CLI-Host");
  if (h==null)    h = head.getURL().getHost();
  String p1 = head.getHeaderField("X-Jenkins-CLI-Port");
  if (p1==null)    p1 = head.getHeaderField("X-Hudson-CLI-Port");   // backward compatibility
  String p2 = head.getHeaderField("X-Jenkins-CLI2-Port");
  String identity = head.getHeaderField("X-Instance-Identity");
  flushURLConnection(head);
  if (p1==null && p2==null) {
    verifyJenkinsConnection(head);
    throw new IOException("No X-Jenkins-CLI2-Port among " + head.getHeaderFields().keySet());
  }
  if (p2!=null)   return new CliPort(new InetSocketAddress(h,Integer.parseInt(p2)),identity,2);
  else            return new CliPort(new InetSocketAddress(h,Integer.parseInt(p1)),identity,1);
}
origin: stackoverflow.com

 public void checkURL(URL url) throws IOException {
  HttpURLConnection conn = (HttpURLConnection) url.openConnection();
  conn.setRequestMethod("GET");
  System.out.println(String.format("Fetching %s ...", url));
  try {
    int responseCode = conn.getResponseCode();
    if (responseCode == 200) {
      System.out.println(String.format("Site is up, content length = %s", conn.getHeaderField("content-length")));
    } else {
      System.out.println(String.format("Site is up, but returns non-ok status = %d", responseCode));
    }
  } catch (java.net.UnknownHostException e) {
    System.out.println("Site is down");
  }
}
origin: stackoverflow.com

URL resourceUrl, base, next;
HttpURLConnection conn;
String location;
...
while (true)
{
  resourceUrl = new URL(url);
  conn        = (HttpURLConnection) resourceUrl.openConnection();
  conn.setConnectTimeout(15000);
  conn.setReadTimeout(15000);
  conn.setInstanceFollowRedirects(false);   // Make the logic below easier to detect redirections
  conn.setRequestProperty("User-Agent", "Mozilla/5.0...");
  switch (conn.getResponseCode())
  {
   case HttpURLConnection.HTTP_MOVED_PERM:
   case HttpURLConnection.HTTP_MOVED_TEMP:
     location = conn.getHeaderField("Location");
     base     = new URL(url);               
     next     = new URL(base, location);  // Deal with relative URLs
     url      = next.toExternalForm();
     continue;
  }
  break;
}
is = conn.openStream();
...
origin: stackoverflow.com

 URLConnection connection = new URL("http://foo.bar/w23afv").openConnection();
String contentType = connection.getHeaderField("Content-Type");
boolean image = contentType.startsWith("image/");
origin: advantageous/qbit

private static String extractResponseString(URLConnection connection) throws IOException {
  /* Handle input. */
  HttpURLConnection http = (HttpURLConnection) connection;
  int status = http.getResponseCode();
  String charset = getCharset(connection.getHeaderField("Content-Type"));
  if (status == 200) {
    return readResponseBody(http, charset);
  } else {
    return readErrorResponseBody(http, status, charset);
  }
}
origin: org.unidal.framework/test-framework

public void display(URL url) {
 try {
   URLConnection urlc = url.openConnection();
   String contentType = urlc.getHeaderField("Content-Type");
   byte[] ba = Files.forIO().readFrom(urlc.getInputStream());
   display(new String(ba, determinCharset(contentType, "utf-8")));
 } catch (Exception e) {
   throw new RuntimeException("Error when accessing URL: " + url, e);
 }
}
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: jenkinsci/jenkins

@SuppressFBWarnings(value = "RCN_REDUNDANT_NULLCHECK_OF_NULL_VALUE", justification = "Due to whatever reason FindBugs reports it fot try-with-resources")
static int sshConnection(String jenkinsUrl, String user, List<String> args, PrivateKeyProvider provider, final boolean strictHostKey) throws IOException {
  Logger.getLogger(SecurityUtils.class.getName()).setLevel(Level.WARNING); // suppress: BouncyCastle not registered, using the default JCE provider
  URL url = new URL(jenkinsUrl + "login");
  URLConnection conn = url.openConnection();
  CLI.verifyJenkinsConnection(conn);
  String endpointDescription = conn.getHeaderField("X-SSH-Endpoint");
origin: advantageous/qbit

private static Response extractResponseObject(URLConnection connection) throws IOException {
  /* Handle input. */
  HttpURLConnection http = (HttpURLConnection) connection;
  int status = http.getResponseCode();
  String charset = getCharset(connection.getHeaderField("Content-Type"));
  String body;
  if (status == 200) {
    body = readResponseBody(http, charset);
  } else {
    body = readErrorResponseBodyDoNotDie(http, status, charset);
  }
  return Response.response(status, http.getHeaderFields(), http.getResponseMessage(), body);
}
origin: stackoverflow.com

URL url = new URL("https://android.clients.google.com/c2dm/send");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setUseCaches(false);
out.close();
int responseCode = conn.getResponseCode();
String updatedAuthToken = conn.getHeaderField(UPDATE_CLIENT_AUTH);
if (updatedAuthToken != null && !auth_key.equals(updatedAuthToken)) {
  Log.i("C2DM",
origin: stackoverflow.com

 final URL uri=new URL(...);
URLConnection ucon;
try
 {
 ucon=uri.openConnection();
 ucon.connect();
 final String contentLengthStr=ucon.getHeaderField("content-length");
 //...
 }
catch(final IOException e1)
 {
 }
origin: advantageous/qbit

private static byte[] extractResponseBytes(URLConnection connection) throws IOException {
  /* Handle input. */
  HttpURLConnection http = (HttpURLConnection) connection;
  int status = http.getResponseCode();
  //System.out.println("CONTENT-TYPE" + connection.getHeaderField("Content-TypeT"));
  if (status == 200) {
    return readResponseBodyAsBytes(http);
  } else {
    String charset = getCharset(connection.getHeaderField("Content-Type"));
    readErrorResponseBody(http, status, charset);
    return null;
  }
}
origin: stackoverflow.com

  URL url = new URL(AUTH_URL);
  HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
  urlConnection.setRequestMethod("POST");
  urlConnection.setDoOutput(true);
  outStreamWriter.close();
  int responseCode = urlConnection.getResponseCode();
FileInputStream fileStream = new FileInputStream(file);
int responseCode = urlConnection.getResponseCode();
    Log.d(TAG, String.format("Headers keys %s.", keys));
    for (String key : keySet) {
      Log.d(TAG, String.format("Header key %s value %s.", key, urlConnection.getHeaderField(key)));          
    URL url = new URL(uploadUrl);
    outStreamWriter.close();
    int responseCode = connection.getResponseCode();
    return connection.getHeaderField("Location");
origin: stackoverflow.com

try {
  fl = new File(System.getProperty("user.home").replace("\\", "/") + "/Desktop/Screenshots.zip");
  dl = new URL("http://ds-forums.com/kyle-tests/uploads/Screenshots.zip");
  os = new FileOutputStream(fl);
  is = dl.openStream();
  dl.openConnection().getHeaderField("Content-Length");
java.netURLConnectiongetHeaderField

Javadoc

Returns the header value at the field position pos or nullif the header has fewer than pos fields. The base implementation of this method returns always null.

Some implementations (notably HttpURLConnection) include a mapping for the null key; in HTTP's case, this maps to the HTTP status line and is treated as being at position 0 when indexing into the header fields.

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
  • connect
    Opens a communications link to the resource referenced by this URL, if such a connection has not alr
  • 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.
  • setDoInput
    Sets the value of the doInput field for thisURLConnection to the specified value. A URL connection c
  • getContentType,
  • setDoInput,
  • addRequestProperty,
  • getURL,
  • getContentEncoding,
  • guessContentTypeFromName,
  • setDefaultUseCaches,
  • getFileNameMap,
  • getContent

Popular in Java

  • Reactive rest calls using spring rest template
  • runOnUiThread (Activity)
  • scheduleAtFixedRate (ScheduledExecutorService)
  • putExtra (Intent)
  • FileOutputStream (java.io)
    An output stream that writes bytes to a file. If the output file exists, it can be replaced or appen
  • URLEncoder (java.net)
    This class is used to encode a string using the format required by application/x-www-form-urlencoded
  • Date (java.util)
    A specific moment in time, with millisecond precision. Values typically come from System#currentTime
  • Properties (java.util)
    A Properties object is a Hashtable where the keys and values must be Strings. Each property can have
  • UUID (java.util)
    UUID is an immutable representation of a 128-bit universally unique identifier (UUID). There are mul
  • Reflections (org.reflections)
    Reflections one-stop-shop objectReflections scans your classpath, indexes the metadata, allows you t
  • Top PhpStorm plugins
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