@RestController
public class HelloWorldController {
@GetMapping(path="/helloWorld")
public String helloWorld() {
return "Hello-World";
}
}
我是 RestFul WebServices 的新手。我試圖用 PostMapping 注釋 helloWorld() 但它失敗了。使用 GetMapping,它成功地被執行。
有人能告訴我為什么不允許 PostMapping 嗎?
uj5u.com熱心網友回復:
PostMapping 對于 POST 請求。
GetMapping 對于 GET 請求。
如果想要呼叫 PostMapping 成功,可以使用 Postman 或 SoapUI、curl 來測驗 HTTP POST 請求。
參考檔案:
- https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/bind/annotation/PostMapping.html
- https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/bind/annotation/GetMapping.html
uj5u.com熱心網友回復:
除了@Do Nhu Vys 的回答。在執行 Post Requests 時,您經常會遇到 CORS 和 CRFS 的問題。
參考:
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 -彈簧框架
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/374201.html
上一篇:獲取sql的值回傳php
