List of usage examples for java.net HttpURLConnection getHeaderFields
public Map<String, List<String>> getHeaderFields()
From source file:Main.java
public static final void appendCookies(final StringBuffer cookie, final HttpURLConnection conn) { List<String> values = conn.getHeaderFields().get("Set-Cookie"); if (values != null) { for (String v : values) { if (v.indexOf("deleted") == -1) { if (cookie.length() > 0) { cookie.append("; "); }//from w ww .jav a2s . c o m cookie.append(v.split(";")[0]); } } } }
From source file:Main.java
/** * Determine whether the response contains a basic authentication challenge. * @param connection the connection from which the response is extracted. * @return <code>true</code> if the response contains an authentication challenge, <code>false</code> otherwise. */// w ww. ja va2s .c om static boolean hasAuthenticationChallenge(HttpURLConnection connection) { Map<String, List<String>> headers = connection.getHeaderFields(); return headers.get(AUTHENTICATION_CHALLENGE_HEADER) != null; }
From source file:Main.java
private static void dumpHeaders(HttpURLConnection conn, PrintStream out) { for (Map.Entry<String, List<String>> e : conn.getHeaderFields().entrySet()) for (String v : e.getValue()) out.println("received header " + e.getKey() + ": " + v); }
From source file:utils.ConnectionUtil.java
public static void printHttpURLConnectionHeaders(HttpURLConnection httpURLConnection) { //////////////////////?????????????????????? print hears of response Map<String, List<String>> s = httpURLConnection.getHeaderFields(); Set<Map.Entry<String, List<String>>> set = s.entrySet(); for (Map.Entry<String, List<String>> ss : set) { System.out.println("key: " + ss.getKey() + " value: " + ss.getValue()); }// w w w . ja v a 2s . c om }
From source file:com.exzogeni.dk.http.HttpTask.java
@NonNull private static Map<String, List<String>> getHeaderFields(HttpURLConnection cn) { final Map<String, List<String>> headers = cn.getHeaderFields(); if (headers != null) { final Map<String, List<String>> localHeaders = new HashMap<>(headers); localHeaders.remove(null);/*from w w w .j a v a 2 s.c o m*/ return Collections.unmodifiableMap(localHeaders); } return Collections.emptyMap(); }
From source file:com.tc.util.io.ServerURL.java
private static String readHeaderFields(HttpURLConnection urlConnection) { StringBuilder sb = new StringBuilder(); Map<String, List<String>> headerFields = urlConnection.getHeaderFields(); for (Map.Entry<String, List<String>> entry : headerFields.entrySet()) { sb.append(entry.getKey()).append("=").append(entry.getValue()) .append(System.getProperty("line.separator")); }/*from w w w . j a v a 2s . c om*/ return sb.toString(); }
From source file:Main.java
public static Reader getUri(URL url) throws IOException { //Log.d(TAG, "getUri: " + url.toString()); boolean useGzip = false; HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setReadTimeout(30 * 1000);//from w ww. j a v a 2 s . c om conn.setRequestProperty("Accept-Encoding", "gzip"); conn.connect(); InputStream in = conn.getInputStream(); final Map<String, List<String>> headers = conn.getHeaderFields(); // This is a map, but we can't assume the key we're looking for // is in normal casing. So it's really not a good map, is it? final Set<Map.Entry<String, List<String>>> set = headers.entrySet(); for (Iterator<Map.Entry<String, List<String>>> i = set.iterator(); i.hasNext();) { Map.Entry<String, List<String>> entry = i.next(); if ("Content-Encoding".equalsIgnoreCase(entry.getKey())) { for (Iterator<String> j = entry.getValue().iterator(); j.hasNext();) { String str = j.next(); if (str.equalsIgnoreCase("gzip")) { useGzip = true; break; } } // Break out of outer loop. if (useGzip) { break; } } } if (useGzip) { return new BufferedReader(new InputStreamReader(new GZIPInputStream(in)), 8 * 1024); } else { return new BufferedReader(new InputStreamReader(in), 8 * 1024); } }
From source file:org.droidparts.http.worker.HttpURLConnectionWorker.java
public static HTTPResponse getReponse(HttpURLConnection conn) throws HTTPException { HTTPResponse response = new HTTPResponse(); response.code = connectAndGetResponseCodeOrThrow(conn); response.headers = conn.getHeaderFields(); response.body = HTTPInputStream.getInstance(conn, false).readAndClose(); return response; }
From source file:org.pixmob.fm2.util.HttpUtils.java
/** * Get Http cookies from a response./*from www .j a va2 s . c o m*/ */ public static void readCookies(HttpURLConnection conn, Set<String> cookies) { final List<String> newCookies = conn.getHeaderFields().get("Set-Cookie"); if (newCookies != null) { for (final String newCookie : newCookies) { cookies.add(newCookie.split(";", 2)[0]); } } }
From source file:org.pixmob.fm2.util.HttpUtils.java
/** * Open the {@link InputStream} of an Http response. This method supports * GZIP responses.//from w w w .ja v a2s .c om */ public static InputStream getInputStream(HttpURLConnection conn) throws IOException { final List<String> contentEncodingValues = conn.getHeaderFields().get("Content-Encoding"); if (contentEncodingValues != null) { for (final String contentEncoding : contentEncodingValues) { if (contentEncoding != null && contentEncoding.contains("gzip")) { return new GZIPInputStream(conn.getInputStream()); } } } return conn.getInputStream(); }