Spring boot: Request method 'DELETE' not supported, Request method 'PUT' not supported, Request method 'POST' not supported


GET,POST,PUT,DELETE, Spring都支持,不要懷疑Spring, 一定是前端發送的rest 請求和后端的響應不匹配,

查找原因以及解決辦法, 很簡單

用chrome打開F12控制台,仔細檢查核對發送到服務端的rest請求的url是否和后端的rest服務匹配,如果不匹配就會出類似錯誤

比如后端服務如果定義是這樣,http://xxx.xxx.xxx/users/abc請求,將刪除用戶abc

@RestController
@RequestMapping(value="/users")
public class UserDataController {
    @RequestMapping(value="{/id}", method=RequestMethod.DELETE)
... ....

如果前端有拼接URL的代碼,比如

var url = "http://xxx.xxx.xxx/users/" + userid 

但如果如果因為bug或者錯誤,導致userid為空,就可能發送的請求是http://host/users/, 這樣就會導致 Request method 'DELETE' not supported, Request method 'PUT' not supported, Request method 'POST' not supported類似的異常


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM