2016-11-16 31 views
3

我试图打的Liferay注销的servlet“C /门/注销”通过Java,但它总是返回400响应:Liferay的注销返回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()); 

} 
+0

你尝试“GET”,而不是“POST”? –

+0

嗨,我已经尝试了GET和POST都没有好像工作 – ravicandy1234

+0

我已经试过你的代码稍微修改没有'USER_AGENT'和'url =“http:// localhost:8080/c/portal/logout”'和' HttpGet'-我收到一个'HTTP/1.1 200 OK'。所以有一些东西在你身边。你可以添加'response.getStatusLine()'的结果吗? –

回答

0

假设你的目的是注销用户会议期间,最好的方法是调用sendRedirectHttpServletResponse参考

public void myPostAction(ActionRequest request, ActionResponse response) throws Exception { 
    // ... 
    response.sendRedirect("/c/portal/logout"); 
} 
+0

这没有提供问题的答案。要批评或要求作者澄清,请在其帖子下方留言。 - [来自评论](/评论/低质量帖/ 14342741) – Danh

+0

注意到并添加了一个说明 – SleepyTonic

+0

嗨昏昏欲睡:谢谢你的回复我知道我可以重定向用户“/ c/portal /注销”,但这会导致重定向,如果已配置任何现有用户登录,调用所有前和后登出挂钩,我需要以静默方式注销重定向。 – ravicandy1234