我试图通过Java命中Liferay注销servlet "c/portal/logout",但它总是返回一个400响应:
private void sendPost() throws Exception {
String url = "localhost:8080/c/portal/logout";
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(url);
// add header
post.setHeader("User-Agent", USER_AGENT);
HttpResponse response = client.execute(post);
System.out.println("nSending 'POST' request to URL : " + url);
BufferedReader rd = new BufferedReader(
new InputStreamReader(response.getEntity().getContent()));
StringBuffer result = new StringBuffer();
String line = "";
while ((line = rd.readLine()) != null) {
result.append(line);
}
System.out.println(result.toString());
}
假设您的目的是注销用户会话,最好的方法是在HttpServletResponse
引用上调用sendRedirect
public void myPostAction(ActionRequest request, ActionResponse response) throws Exception {
// ...
response.sendRedirect("/c/portal/logout");
}