简体   繁体   English

Spring Boot 和 Ajax 中不允许使用 405 方法

[英]405 Method not allowed in Spring Boot and Ajax

Hi I am having request mapping like this嗨,我有这样的请求映射

@RequestMapping(value = "/pendodnp/{visitorId}/{content}")
public ResponseEntity<Object> setPendoDNP(@PathVariable String visitorId, @PathVariable String content, final HttpSession session, final HttpServletRequest request) throws PendoException {
    LOGGER.info("### pendodnp");
    _splitService.updateDNP(visitorId, content);
    return ResponseEntity.ok().body(content);
}

but when I hit this URL from an angular function, it gives "405 method not allowed" error.但是当我从 angular function 中点击这个 URL 时,它给出了“不允许 405 方法”错误。

    $http.get("pendodnp/"+visitorId+"/"+dnpValue, JSON.stringify(dnpValue))
        .success(function(response) {

Here is screenshot of how the request is going, can someone tell me what i am missing here?这是请求进行情况的屏幕截图,有人可以告诉我我在这里缺少什么吗?

在此处输入图像描述

You haven't specified which HTTP method (GET, POST, PUT, DELETE, etc) the mapping should handle.您尚未指定映射应处理的 HTTP 方法(GET、POST、PUT、DELETE 等)。 To do that either use @GetMapping or change your @RequestMapping so it includes the method parameter.为此,请使用@GetMapping或更改您的@RequestMapping以使其包含method参数。

@GetMapping("/pendodnp/{visitorId}/{content}")

Or或者

import static org.springframework.web.bind.annotation.RequestMethod.GET;
...
@RequestMapping(method = GET, path = "/pendodnp/{visitorId}/{content}")

Using @RequestMapping without a method parameter is usually only done at the class level, not individual methods.在没有method参数的情况下使用@RequestMapping通常只在class级别完成,而不是单个方法。 @GetMapping (or @PostMapping , @PutMapping , etc) are more common on controller methods . @GetMapping (或@PostMapping@PutMapping等)在 controller方法上更常见。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 405 Spring不允许的方法 - 405 Method Not Allowed with Spring Spring启动应用程序Post方法调用,405:方法不允许 - Spring boot application Post method invocation, 405: Method Not Allowed 405不允许的方法:请求方法&#39;POST&#39;不支持| Ajax / Spring MVC - 405 Method Not Allowed : Request method 'POST' not supported | Ajax/Spring MVC Spring 启动 REST API 一直说 405 - 方法不允许 - Spring Boot REST API keeps saying 405 - Method Not Allowed 405 方法不允许,spring 启动,但我使用 csrf 令牌 header - 405 Method Not Allowed, spring boot, but i used csrf token header 出现意外错误(类型=不允许的方法,状态=405)。 spring 引导不支持请求方法“GET” - There was an unexpected error (type=Method Not Allowed, status=405). Request method 'GET' not supported with spring boot 为什么从Firefox到Spring Boot应用的POST无法获得405方法 - Why does a POST from Firefox to a Spring Boot app get 405 Method not allowed 无法使用 Spring 引导微服务中的 Keycloak 的访问令牌发出请求(不允许使用休息模板问题 405 方法) - Cannot make a request with Access Token from Keycloak in Spring Boot Microservices (Rest Template Issue 405 Method Not Allowed) Spring 3.1中不允许405方法进行HTTP POST - 405 Method Not Allowed for HTTP POST in Spring 3.1 Spring Post:不允许使用HTTP / 1.1 405方法 - Spring Post: HTTP/1.1 405 Method Not Allowed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM