当前位置: 首页>>代码示例>>Java>>正文


Java URLConnection.getRequestProperties方法代码示例

本文整理汇总了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();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:41,代码来源:JavaApiConverter.java


注:本文中的java.net.URLConnection.getRequestProperties方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。