`

restlet中获取头信息

 
阅读更多
restlet框架中,获取http头信息的内容:
1. 在server端,resource中,可以写个方法,直接调用。
	protected Map<String,String> getHeader() {
		Form headForm = (Form) getRequest().getAttributes().get(
				"org.restlet.http.headers");
		return headForm.getValuesMap();
	}


2. 在client端,可以通过
Form headForm = (Form)client.getResponse().getAttributes().get("org.restlet.http.headers");


现在是我在做url重定向时的一个测试用例,模拟post请求:
client = new ClientResource("http://xxx");
String xml = "<?xml version="+ "\"1.0\"" + " encoding=" + "\"UTF-8\"" + "?>" +
		"<request><operation>getrequest</operation>"+</request>";
StringRepresentation representation=new StringRepresentation(xml, MediaType.TEXT_XML);
client.post(representation);  
Form headForm = (Form)client.getResponse().getAttributes().get("org.restlet.http.headers");
System.out.println(headForm.getValues("Location"));

最后输出的是301返回页面头信息中,重定向url值。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics