![](/img/trans.png)
[英]Spring boot and React js Paypal Rest api payment gateway
[英]React JS with Spring boot API REST
我有一個用React JS開發的前端webapp,還有一個用Spring boot構建的rest API。 當我嘗試從我的react-app訪問API時,出現403錯誤。 我的API Rest已部署在tomcat服務器中。
POST http://localhost:8080/fantasy/api/auth/signin 403
PostData.js:3 Uncaught (in promise) SyntaxError: Unexpected end of JSON input
您的ReactJs應用程序和Spring Boot應用程序很可能在不同的端口下運行,並且您沒有在Spring Rest映射方法中配置CORS以便啟用運行ReactJs的host:port的傳入請求:
@CrossOrigin(origins = "http://localhost:4200")
@GetMapping("/user")
public Greeting getUser(){}
您也可以在Controller本身上定義它:
@CrossOrigin(origins = "http://localhost:4200")
@RestController
您還可以為整個應用程序注冊一個單獨的CORS過濾器: 參考
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.