本文整理了Java中java.net.HttpURLConnection.getHeaderFields()
方法的一些代码示例,展示了HttpURLConnection.getHeaderFields()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpURLConnection.getHeaderFields()
方法的具体详情如下:
包路径:java.net.HttpURLConnection
类名称:HttpURLConnection
方法名:getHeaderFields
暂无
代码示例来源:origin: square/okhttp
@Override public Map<String, List<String>> getHeaderFields() {
return delegate.getHeaderFields();
}
代码示例来源:origin: libgdx/libgdx
@Override
public Map<String, List<String>> getHeaders () {
return connection.getHeaderFields();
}
代码示例来源:origin: libgdx/libgdx
@Override
public Map<String, List<String>> getHeaders () {
return connection.getHeaderFields();
}
代码示例来源:origin: prestodb/presto
@Override public Map<String, List<String>> getHeaderFields() {
return delegate.getHeaderFields();
}
代码示例来源:origin: looly/hutool
/**
* 获取所有Http请求头
*
* @return Http请求头Map
*/
public Map<String, List<String>> headers() {
return this.conn.getHeaderFields();
}
代码示例来源:origin: looly/hutool
/**
* 获取所有Http请求头
*
* @return Http请求头Map
*/
public Map<String, List<String>> headers() {
return this.conn.getHeaderFields();
}
代码示例来源:origin: yanzhenjie/NoHttp
@Override
public Map<String, List<String>> getResponseHeaders() {
return mUrlConnection.getHeaderFields();
}
代码示例来源:origin: yanzhenjie/NoHttp
@Override
public Map<String, List<String>> getResponseHeaders() {
return mUrlConnection.getHeaderFields();
}
代码示例来源:origin: google/ExoPlayer
@Override
public Map<String, List<String>> getResponseHeaders() {
return connection == null ? Collections.emptyMap() : connection.getHeaderFields();
}
代码示例来源:origin: square/okhttp
/**
* Extracts OkHttp headers from the supplied {@link java.net.HttpURLConnection}. Only real headers
* are extracted. See {@link #extractStatusLine(java.net.HttpURLConnection)}.
*/
private static Headers extractOkResponseHeaders(
HttpURLConnection httpUrlConnection, Response.Builder okResponseBuilder) {
Map<String, List<String>> javaResponseHeaders = httpUrlConnection.getHeaderFields();
return extractOkHeaders(javaResponseHeaders, okResponseBuilder);
}
代码示例来源:origin: spotify/helios
private boolean isGzipCompressed(final HttpURLConnection connection) {
final List<String> encodings = connection.getHeaderFields().get("Content-Encoding");
if (encodings == null) {
return false;
}
for (final String encoding : encodings) {
if ("gzip".equals(encoding)) {
return true;
}
}
return false;
}
});
代码示例来源:origin: google/agera
@NonNull
private static Map<String, String> getHeader(@NonNull final HttpURLConnection connection) {
final Map<String, String> headers = new HashMap<>();
for (final Entry<String, List<String>> header : connection.getHeaderFields().entrySet()) {
final String key = header.getKey();
if (key != null) {
headers.put(key.toLowerCase(US), header.getValue().get(0));
}
}
return headers;
}
代码示例来源:origin: facebook/stetho
public URLConnectionInspectorResponse(String requestId, HttpURLConnection conn) throws IOException {
super(Util.convertHeaders(conn.getHeaderFields()));
mRequestId = requestId;
mUrl = conn.getURL().toString();
mStatusCode = conn.getResponseCode();
mStatusMessage = conn.getResponseMessage();
}
代码示例来源:origin: wildfly/wildfly
/**
* Examines the response's header fields and returns a Map from String to List of Strings
* representing the object's metadata.
*/
private static Map extractMetadata(HttpURLConnection connection) {
TreeMap metadata=new TreeMap();
Map headers=connection.getHeaderFields();
for(Iterator i=headers.keySet().iterator(); i.hasNext();) {
String key=(String)i.next();
if(key == null) continue;
if(key.startsWith(Utils.METADATA_PREFIX)) {
metadata.put(key.substring(Utils.METADATA_PREFIX.length()), headers.get(key));
}
}
return metadata;
}
代码示例来源:origin: alibaba/nacos
private static HttpResult getResult(HttpURLConnection conn) throws IOException {
int respCode = conn.getResponseCode();
InputStream inputStream;
if (HttpURLConnection.HTTP_OK == respCode) {
inputStream = conn.getInputStream();
} else {
inputStream = conn.getErrorStream();
}
Map<String, String> respHeaders = new HashMap<String, String>(conn.getHeaderFields().size());
for (Map.Entry<String, List<String>> entry : conn.getHeaderFields().entrySet()) {
respHeaders.put(entry.getKey(), entry.getValue().get(0));
}
String gzipEncoding = "gzip";
if (gzipEncoding.equals(respHeaders.get(HttpHeaders.CONTENT_ENCODING))) {
inputStream = new GZIPInputStream(inputStream);
}
HttpResult result = new HttpResult(respCode, IOUtils.toString(inputStream, getCharset(conn)), respHeaders);
inputStream.close();
return result;
}
代码示例来源:origin: alibaba/nacos
private static HttpResult getResult(HttpURLConnection conn) throws IOException {
int respCode = conn.getResponseCode();
InputStream inputStream;
if (HttpURLConnection.HTTP_OK == respCode
|| HttpURLConnection.HTTP_NOT_MODIFIED == respCode) {
inputStream = conn.getInputStream();
} else {
inputStream = conn.getErrorStream();
}
Map<String, String> respHeaders = new HashMap<String, String>(conn.getHeaderFields().size());
for (Map.Entry<String, List<String>> entry : conn.getHeaderFields().entrySet()) {
respHeaders.put(entry.getKey(), entry.getValue().get(0));
}
String encodingGzip = "gzip";
if (encodingGzip.equals(respHeaders.get(HttpHeaders.CONTENT_ENCODING))) {
inputStream = new GZIPInputStream(inputStream);
}
return new HttpResult(respCode, IoUtils.toString(inputStream, getCharset(conn)), respHeaders);
}
代码示例来源:origin: nutzam/nutz
protected NutMap getResponseHeader() throws IOException {
if (conn.getResponseCode() < 0) {
throw new IOException("Network error!! resp code=" + conn.getResponseCode());
}
NutMap re = new NutMap();
re.putAll(conn.getHeaderFields());
return re;
}
代码示例来源:origin: nutzam/nutz
public void afterResponse(Request request, HttpURLConnection conn, Response response) {
Map<String, List<String>> props = conn.getHeaderFields();
for (Entry<String, List<String>> en : props.entrySet()) {
if (en.getKey() == null || !en.getKey().equalsIgnoreCase("Set-Cookie")) {
continue;
}
for (String e : en.getValue()) {
if (debug)
log.debugf("found Set-Cookie [%s]", e);
this.parse(e);
}
break;
}
}
代码示例来源:origin: google/agera
@Test
public void shouldNotPassOnNullResponseHeader() throws Throwable {
final ByteArrayInputStream inputStream = new ByteArrayInputStream(RESPONSE_BODY);
when(mockHttpURLConnection.getInputStream()).thenReturn(inputStream);
when(mockHttpURLConnection.getContentLength()).thenReturn(RESPONSE_BODY.length);
final Map<String, List<String>> headerFields = new HashMap<>();
headerFields.put(null, singletonList("value"));
headerFields.put("naMe2", singletonList("value2"));
when(mockHttpURLConnection.getHeaderFields()).thenReturn(headerFields);
final HttpResponse httpResponse = httpFunction().apply(HTTP_GET_REQUEST).get();
assertThat(httpResponse.header.size(), is(1));
assertThat(httpResponse.header, hasEntry("name2", "value2"));
verify(mockHttpURLConnection).disconnect();
}
代码示例来源:origin: google/agera
@Test
public void shouldPassOnResponseHeadersAsLowerCase() throws Throwable {
final ByteArrayInputStream inputStream = new ByteArrayInputStream(RESPONSE_BODY);
when(mockHttpURLConnection.getInputStream()).thenReturn(inputStream);
when(mockHttpURLConnection.getContentLength()).thenReturn(RESPONSE_BODY.length);
final Map<String, List<String>> headerFields = new HashMap<>();
headerFields.put("NAmE", singletonList("value"));
headerFields.put("naMe2", singletonList("value2"));
when(mockHttpURLConnection.getHeaderFields()).thenReturn(headerFields);
final HttpResponse httpResponse = httpFunction().apply(HTTP_GET_REQUEST).get();
assertThat(httpResponse.header.size(), is(2));
assertThat(httpResponse.header, hasEntry("name", "value"));
assertThat(httpResponse.header, hasEntry("name2", "value2"));
verify(mockHttpURLConnection).disconnect();
}
内容来源于网络,如有侵权,请联系作者删除!