本文整理汇总了Java中java.net.URLConnection.getRequestProperties方法的典型用法代码示例。如果您正苦于以下问题:Java URLConnection.getRequestProperties方法的具体用法?Java URLConnection.getRequestProperties怎么用?Java URLConnection.getRequestProperties使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.net.URLConnection
的用法示例。
在下文中一共展示了URLConnection.getRequestProperties方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: varyHeaders
import java.net.URLConnection; //导入方法依赖的package包/类
private static Headers varyHeaders(URLConnection urlConnection, Headers responseHeaders) {
if (HttpHeaders.hasVaryAll(responseHeaders)) {
// "*" means that this will be treated as uncacheable anyway.
return null;
}
Set<String> varyFields = HttpHeaders.varyFields(responseHeaders);
if (varyFields.isEmpty()) {
return new Headers.Builder().build();
}
// This probably indicates another HTTP stack is trying to use the shared ResponseCache.
// We cannot guarantee this case will work properly because we cannot reliably extract *all*
// the request header values, and we can't get multiple Vary request header values.
// We also can't be sure about the Accept-Encoding behavior of other stacks.
if (!(urlConnection instanceof CacheHttpURLConnection
|| urlConnection instanceof CacheHttpsURLConnection)) {
return null;
}
// This is the case we expect: The URLConnection is from a call to
// JavaApiConverter.createJavaUrlConnection() and we have access to the user's request headers.
Map<String, List<String>> requestProperties = urlConnection.getRequestProperties();
Headers.Builder result = new Headers.Builder();
for (String fieldName : varyFields) {
List<String> fieldValues = requestProperties.get(fieldName);
if (fieldValues == null) {
if (fieldName.equals("Accept-Encoding")) {
// Accept-Encoding is special. If OkHttp sees Accept-Encoding is unset it will add
// "gzip". We don't have access to the request that was actually made so we must do the
// same.
result.add("Accept-Encoding", "gzip");
}
} else {
for (String fieldValue : fieldValues) {
Internal.instance.addLenient(result, fieldName, fieldValue);
}
}
}
return result.build();
}