gpt4 book ai didi

java - Liferay 注销返回 400 响应

转载 作者:搜寻专家 更新时间:2023-11-01 03:47:38 25 4
gpt4 key购买 nike

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

}

最佳答案

假设您的意图是注销用户 session ,最好的方法是在 HttpServletResponse 引用上调用 sendRedirect

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

关于java - Liferay 注销返回 400 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40624540/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com