|
楼主 |
发表于 2014-6-19 10:46:07
|
显示全部楼层
本帖最后由 a2862433 于 2014-6-19 10:47 编辑
jishuang 发表于 2014-6-19 10:35
确认是具体怎么操作的时候会提示session超时
登出的代码如下
// 注销
public void logout(String bSessionID) throws HttpException, JSONException, IOException {
Map<String, String> params = new HashMap<String, String>();
params.put("bsessionid", bSessionID);
sendRequestByGet(getLogoutURL(), params);
}
// 注销请求
private String getLogoutURL() {
return address + "/demo/actions/process/integration/x5Logout.j";
}
// 以get方式发送请求
private JSONObject sendRequestByGet(String url, Map<String, String> params) throws HttpException, JSONException, IOException {
PostMethod method = new PostMethod(url);
for (String key : params.keySet()) {
method.setParameter(key, params.get(key));
}
long length = method.getRequestEntity().getContentLength();
method.setRequestHeader("Content-Length", length + "");
try {
HttpClient httpClient = new HttpClient();
int status = httpClient.executeMethod(method);
if (status != HttpStatus.SC_OK) {
throw new RuntimeException(String.format("远程服务器%s调用失败! \n%s", address, method.getStatusLine()));
}
InputStream stream = method.getResponseBodyAsStream();
JSONObject result = new JSONObject(streamToString(stream));
if (!result.getBoolean("flag")) {
throw new RuntimeException(String.format("远程服务器%s调用成功,但返回错误! \n%s", address, result.getString("message")));
}
return result;
} finally {
method.releaseConnection();
}
} |
|