1
我有一个关于Spring MVC/Rest的问题。Spring MVC/REST只从某个域检索数据
说我有一种服务,您可以通过输入以下URL http://localhost:8080/project/api/get/user/1
来检索用户的用户详细信息(JSON)。
我的前端应用程序在:http://localhost:9000/
上运行,我可以从API中获取数据。但是,我可以在任何域上执行此操作。我的目标是只提供一个(或一系列)域名/ ips。
所以我增加了以下过滤器,以我的API为它只能从本地主机接受电话:9000个
@Component
public class CORSFilter extends OncePerRequestFilter {
@Override
protected void doFilterInternal(HttpServletRequest req, HttpServletResponse res, FilterChain filterChain)
throws ServletException, IOException {
res.addHeader("Access-Control-Allow-Origin","http://localhost:9000");
/* other code*/
现在确实阻止其他域调用。但是,如果我使用邮递员这样的工具,我仍然可以获取数据!我错过了什么吗?这是我在这里做的安全和正确的方式吗?如果我使用邮差,为什么我仍然能够获取甚至发布数据?