Home > Mobile >  GetMapping and PostMapping
GetMapping and PostMapping

Time:12-01

@RestController public class HelloWorldController {

@GetMapping(path="/helloWorld")
public String helloWorld() {
    return "Hello-World";
}

}

I am new to RestFul WebServices. I tried to annotate the helloWorld() with PostMapping but it failed. Using GetMapping, it successfully gets executed.

Can somebody tell me why PostMapping was not allowed?

CodePudding user response:

PostMapping for POST request.

GetMapping for GET request.

If you want call PostMapping success, you can use Postman or SoapUI, curl for testing HTTP POST request.

Reference document:

CodePudding user response:

In addition to @Do Nhu Vys answer. You will often encounter problems with CORS and CRFS while performing Post Requests.

References:

https://docs.spring.io/spring-security/site/docs/5.0.x/reference/html/csrf.html https://spring.io/blog/2015/06/08/cors-support-in-spring-framework

  • Related