Liferay logout返回400响应



我试图通过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");
}

相关内容

  • 没有找到相关文章

最新更新