本文整理汇总了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);
}