【发布时间】:2017-10-26 05:55:31
【问题描述】:
我目前对一种情况感到非常困惑,我有以下一段代码:
public String loginDetail(CloseableHttpClient httpClient, Userinfo user) throws Exception {
HttpPost httppost = null;
try {
List<NameValuePair> formParams = new ArrayList<NameValuePair>();
formParams.add(new BasicNameValuePair("j_username", user.getUsername()));
formParams.add(new BasicNameValuePair("j_password", user.getPassword()));
HttpEntity loginEntity = new UrlEncodedFormEntity(formParams, "UTF-8");
httppost = new HttpPost("http://<URL>/j_spring_security_check");
httppost.setEntity(loginEntity);
CloseableHttpResponse loginResponse = httpClient.execute(httppost);
String responseStr = new String(EntityUtils.toString(loginResponse.getEntity()).getBytes("ISO_8859_1"),
"GBK");
loginResponse.close();
if (responseStr.contains("/common/index.jsp")) {
return "Success";
} else if (responseStr.contains("error=2")) {
Utils.recordIncorrectUser(user);
return Constants.INVALID_USER;
} else if (!responseStr.contains("error=3")) {
return Constants.InvalidPassword;
}
return Constants.SYS_ERROR;
} finally {
if (httppost != null) {
httppost.abort();
}
}
}
问题是,当我在独立应用程序中运行上述代码时,它可以正常工作并返回来自网站的响应,但是当我将相同的代码放入 tomcat Web 应用程序并访问相同的 URL 时,它会返回给我404 错误。 “HTTP 错误 404。未找到请求的资源。”
谁能帮助我为什么会发生这种情况?有什么与重定向有关的东西吗?
编辑: 我刚刚意识到它无法从tomcat中的web应用程序访问任何外部URL,但从独立应用程序我可以访问所有,我需要在tomcat中进行任何配置吗?
【问题讨论】:
-
检查您的网址 |检查tomcat是否正常启动?
-
是的,tomcat 已经启动并运行,我可以调试它,所有的内部 web 服务也可以访问,要添加的一件事是我正在访问的 url 是外部 URL
标签: tomcat web-applications http-post