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 );
URL url = new URL(url); HttpURLConnection ucon = (HttpURLConnection) url.openConnection(); ucon.setInstanceFollowRedirects(false); URL secondURL = new URL(ucon.getHeaderField("Location")); URLConnection conn = secondURL.openConnection();
@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); }
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; } }
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(); }
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"); }
/** * 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); }
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"); } }
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(); ...
URLConnection connection = new URL("http://foo.bar/w23afv").openConnection(); String contentType = connection.getHeaderField("Content-Type"); boolean image = contentType.startsWith("image/");
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); } }
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); } }
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);
@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");
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); }
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",
final URL uri=new URL(...); URLConnection ucon; try { ucon=uri.openConnection(); ucon.connect(); final String contentLengthStr=ucon.getHeaderField("content-length"); //... } catch(final IOException e1) { }
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; } }
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");
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");