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


Java HttpResponse.getHeaders方法代码示例

本文整理汇总了Java中com.google.api.client.http.HttpResponse.getHeaders方法的典型用法代码示例。如果您正苦于以下问题:Java HttpResponse.getHeaders方法的具体用法?Java HttpResponse.getHeaders怎么用?Java HttpResponse.getHeaders使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.api.client.http.HttpResponse的用法示例。


在下文中一共展示了HttpResponse.getHeaders方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: hasMetadataServer

import com.google.api.client.http.HttpResponse; //导入方法依赖的package包/类
private static boolean hasMetadataServer(HttpTransport transport) {
  try {
    HttpRequest request = transport.createRequestFactory()
        .buildGetRequest(new GenericUrl(METADATA_SERVER_URL));
    HttpResponse response = request.execute();
    HttpHeaders headers = response.getHeaders();
    return "Google".equals(headers.getFirstHeaderStringValue("Metadata-Flavor"));
  } catch (IOException | RuntimeException expected) {
    // If an error happens, it's probably safe to say the metadata service isn't available where
    // the code is running. We have to catch ApiProxyException due to the new dev server returning
    // a different error for unresolvable hostnames. Due to not wanting to put a required
    // dependency on the App Engine SDK here, we catch the generic RuntimeException and do a
    // class name check.
    if (expected instanceof RuntimeException
        && !API_PROXY_EXCEPTION_CLASS_NAME.equals(expected.getClass().getName())
        && !REMOTE_API_EXCEPTION_CLASS_NAME.equals(expected.getClass().getName())) {
      throw (RuntimeException) expected;
    }
  }
  return false;
}
 
开发者ID:cloudendpoints,项目名称:endpoints-management-java,代码行数:22,代码来源:ControlFilter.java

示例2: execute

import com.google.api.client.http.HttpResponse; //导入方法依赖的package包/类
public Pong execute() throws IOException {
    HttpResponse response = this.httpRequest.execute();

    HttpHeaders headers = response.getHeaders();
    String version = headers.getFirstHeaderStringValue("X-Rqlite-Version");

    return new Pong(version);
}
 
开发者ID:rqlite,项目名称:rqlite-java,代码行数:9,代码来源:PingRequest.java


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