【问题标题】:Accessing Spring Rest with 404 error使用 404 错误访问 Spring Rest
【发布时间】:2014-09-12 12:19:05
【问题描述】:

我在我的项目中使用 Spring MVC,在将用户请求映射到 URI 时,我收到 404 错误。但是我可以访问其他控制器。

工作控制器

@RequestMapping(value = "groupview.htm", method = RequestMethod.GET)
    public String showGroups(
            @ModelAttribute("groupRegistrationDTO") GroupRegistrationDTO groupRegistrationDTO,
            BindingResult result, Model model,
            HttpServletRequest httpServletRequest) {

GroupsResultDTO groupsResultDTO = manageGroupBusiness.getGroups(
                groupRegistrationDTO, result, model);


return "showGroups";
}

使用显示所需输出的 ​​java 类进行测试

private static void wsRequest(String jsonInput) {
        try {

            URL url = new URL("http://localhost:5080/myservlet/groupview.htm");
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("POST");
            conn.setRequestProperty("Accept","*/*");
            conn.setRequestProperty("Authorization", "Basic "
                    + getBasicAuthenticationEncoding());

            if (conn.getResponseCode() != 200) {
                throw new RuntimeException("Failed : HTTP error code : "
                        + conn.getResponseCode());
            }

            BufferedReader br = new BufferedReader(new InputStreamReader(
                    (conn.getInputStream())));

            String output;
            System.out.println("Output from Server .... \n");
            while ((output = br.readLine()) != null) {
                System.out.println(output);
            }

            conn.disconnect();

        } catch (MalformedURLException e) {

            e.printStackTrace();

        } catch (IOException e) {

            e.printStackTrace();

        }

    }

现在我有另一个控制器,当我尝试使用海报插件或通过 java 网络 URL 连接(使用 requestmethod 发布)测试它时,它是一个安静的服务。我得到 404 响应代码。

尝试使用 URL 访问:

http://localhost:5080/myservlet/authAndRegDevice.htm

休息服务控制器

@RequestMapping(value = "authAndRegDevice.htm", method = RequestMethod.POST)
@ResponseBody
public String authenticateAndRegisterDevice(
        @RequestBody String notificationJsonRequest){

return "success";
}

为什么第二个控制器在第一个控制器工作时会出现 404 错误。 有人可以帮我解决这个问题吗

【问题讨论】:

  • 当您调用localhost:5080/myservlet/authAndRegDevice.htm 时,您是否正在为第二次调用发送 Json 作为请求正文?和 ;最后是意外还是您调用了相同的网址?
  • 第二种方法的bean控制器注册了吗?
  • @shazin : 是的,我将 json 输入作为请求正文发送,我想得到关于同一 url 的第二个问题
  • localhost:5080/myservlet/authAndRegDevice.htm;最后你有一个';'这是必需的还是偶然的?
  • 不,这是不小心保存在帖子中的。在我原来的帖子中更新

标签: java spring


【解决方案1】:

这个问题可以在这里关闭,因为我已经提出了另一个帖子,其中包含详细的问题以及我所面临的确切失败。

Bypass spring security with java URL connection

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-12-13
    • 2020-04-10
    • 2015-04-24
    • 2017-03-15
    • 1970-01-01
    • 1970-01-01
    • 2016-04-12
    • 2020-04-12
    相关资源
    最近更新 更多