當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。