Java HTTP Response getResponseHeaders(URLConnection conn, HashMap headers)

Here you can find the source of getResponseHeaders(URLConnection conn, HashMap headers)

Description

Gets the headers

License

Apache License

Parameter

Parameter Description
conn a parameter
headers a parameter

Return

1st response line

Declaration

public static String getResponseHeaders(URLConnection conn, HashMap<String, String> headers) 

Method Source Code

//package com.java2s;
// Licensed under the Apache License, Version 2.0 (the "License");

import java.net.URLConnection;
import java.util.HashMap;

public class Main {
    /**//from w  w w.ja va  2s . co  m
     * Gets the headers
     * 
     * @param conn
     * @param headers
     * @return 1st response line
     */
    public static String getResponseHeaders(URLConnection conn, HashMap<String, String> headers) {
        headers.clear();
        String responseCode = "";
        for (int i = 0;; i++) {
            String name = conn.getHeaderFieldKey(i);
            String value = conn.getHeaderField(i);
            if (name == null && value == null) {
                break;
            }
            if (name == null) {
                responseCode = value;
            } else {
                headers.put(name, value);
            }
        }
        return responseCode;
    }
}

Related

  1. getResponseContent(HttpURLConnection httpConn)
  2. getResponseContent(String url)
  3. getResponseErrorContent(HttpURLConnection httpConn)
  4. getResponseHeader(HttpURLConnection conn)
  5. getResponseHeader(String headerName, HttpURLConnection urlConnection)
  6. getResponseMessage(InputStream inputStream, HttpURLConnection connection)
  7. getResponseStream(final HttpURLConnection connection)
  8. getResponseStream(HttpURLConnection conn)
  9. getResponseStringFromConn(HttpURLConnection conn, boolean isSuccess)