Java Liferay注销返回400响应
我试图通过Java点击Liferay注销servlet“c/portal/logout”,但它总是返回400响应:Java Liferay注销返回400响应,java,liferay-6,httpconnection,Java,Liferay 6,Httpconnection,我试图通过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); //
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");
}
你试过“GET”而不是“POST”吗?嗨,我试过GET和POST都没有效果。我试过在没有
USER\u AGENT
和url=”的情况下稍微修改你的代码http://localhost:8080/c/portal/logout“
和HttpGet
-我收到一个HTTP/1.1200 OK
。所以你这边少了点什么。您是否可以添加响应的结果。getStatusLine()
?查看您配置的servlet筛选器。例如,CASFilter
将在logoutHi上重定向到PropsKey.CAS\u LOGOUT\u URL
:感谢您的回复我知道我可以重定向用户“/c/portal/LOGOUT”但这会导致重定向,如果任何现有用户登录时调用所有注销前和注销后挂钩(如果已配置),我需要静默注销。@ravicandy1234:据我所知,/c/portal/logout
不是全局注销操作。如果您可以保留所有实时会话,则可以调用PortalSessionContext.get(sessionId).invalidate()
,但不会执行筛选器。嗯