【问题标题】:URL Returns 404 from tomcatURL从tomcat返回404
【发布时间】: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


【解决方案1】:

好吧,它得到了解决,就我而言,我执行了以下操作

  1. 禁用了我的防火墙(没用)
  2. 删除了我的防病毒软件 (avira) 并重新启动了我的计算机(vola 它工作正常)

希望对遇到此类问题的人有所帮助

编辑:我发现的另一个问题是我正在使用 Astrill VPN,它导致作为本地解析器工作,这就是为什么它给出 404 错误退出它也有帮助

【讨论】:

    猜你喜欢
    • 2021-08-05
    • 1970-01-01
    • 1970-01-01
    • 2021-02-21
    • 2019-12-03
    • 2017-05-24
    • 2016-10-18
    • 2018-08-17
    • 1970-01-01
    相关资源
    最近更新 更多