如何从标头获取上次修改日期到字符串
我已经在标头对象中获得了标头值。但我需要将“Last-Modified”放入字符串对象中进行比较。请您告诉我如何将最后一个标头放入字符串中。
HttpClient client = new DefaultHttpClient();
//HttpGet get = new HttpGet(url);
HttpHead method = new HttpHead(url);
HttpResponse response = client.execute(method);
Header[] s = response.getAllHeaders();
String sh = String.valueOf(s);
System.out.println("The value of sh:"+sh);
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());
}
String last-modified = // here I need to convert this header(last-modified);
I have got the Header values in Header Object. but I need "Last-Modified" into the string object for comparison. Please could you tell me how should I get the last header into the string.
HttpClient client = new DefaultHttpClient();
//HttpGet get = new HttpGet(url);
HttpHead method = new HttpHead(url);
HttpResponse response = client.execute(method);
Header[] s = response.getAllHeaders();
String sh = String.valueOf(s);
System.out.println("The value of sh:"+sh);
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());
}
String last-modified = // here I need to convert this header(last-modified);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在许多情况下,您只获得一个 Last-Modified 标头,因此您可以简单地使用:
对于多个值,JavaDoc 表示:如果具有给定名称的响应标头存在并且包含多个值,则使用第一个添加的值将被退回。
In many circumstances, you get just one Last-Modified header, so you could simply use:
For multiple values, the JavaDoc says: If a response header with the given name exists and contains multiple values, the value that was added first will be returned.
尝试这样的事情:
Try something like this: