如何用Java写一个head接口
了解到“HEAD方法与 GET 方法类似,也是请求从服务器获取资源,服务器的处理机制也是一样的,但服务器不会返回请求的实体数据,只会传回响应头,也就是资源的“元信息”。”
想学习写一个head方法的接口,返回自定义的响应头信息,但不知道如何实现,网上搜不到相关demo,请问应该怎么写,谢谢~
@RequestMapping(method = RequestMethod.HEAD, path = "head")
public String head(){
DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.CHINA);
DateFormat timeFormat = DateFormat.getTimeInstance(DateFormat.MEDIUM, Locale.CHINA);
String time = dateFormat.format(new Date()) + " " + timeFormat.format(new Date());
index ++;
return time + " -- this is a HEAD method request " + "from consumer: " + appname + " -- " + request.getServerName() + ":" + request.getServerPort() +
" - with version: " + version + " ++ index:" + (index - 1) + "\r\n";
}