如何使用HTTPClient的HEAD方法获取所有标头 [英] how to use HEAD method of HTTPClient to get all headers
本文介绍了如何使用HTTPClient的HEAD方法获取所有标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须使用HttpClient
的HEAD
方法来获取标头字段并检查服务器文件的最后修改"日期.
我无法获取,如果您知道如何获取标题字段,请回复.
如何将最后修改的"标头放入String对象以进行比较.
I have to use HEAD
method of HttpClient
to get the header field and to check the "last-modified" date of server file.
I am not able to get that, if you know how to get the header field then please reply.
How to get the "last-modified" header into the String object for the comparison.
这是我的代码:
HttpClient client = new DefaultHttpClient();
//HttpGet get = new HttpGet(url);
HttpHead method = new HttpHead(url);
HttpResponse response= client.execute(method);
Header[] s = response.getAllHeaders();
System.out.println("THe header from the httpclient:");
for(int i=0; i < s.length; i++){
Header hd = s[i];
System.out.println("Header Name: "+hd.getName()
+" "+" Header Value: "+ hd.getValue());
}
推荐答案
在httpClient 4.5上,您将使用:
On httpClient 4.5 you would use:
final HttpHead headMethod = new HttpHead(fileUri);
final Header header = headMethod.getFirstHeader("last-modified");
final String lastModified = header.getValue();
这篇关于如何使用HTTPClient的HEAD方法获取所有标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文