本文整理匯總了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;
}
示例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);
}