我試圖打的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());
}
你嘗試「GET」,而不是「POST」? –
嗨,我已經嘗試了GET和POST都沒有好像工作 – ravicandy1234
我已經試過你的代碼稍微修改沒有'USER_AGENT'和'url =「http:// localhost:8080/c/portal/logout」'和' HttpGet'-我收到一個'HTTP/1.1 200 OK'。所以有一些東西在你身邊。你可以添加'response.getStatusLine()'的結果嗎? –