【问题标题】:how to disable the cors request while redirecting to another url如何在重定向到另一个 url 时禁用 cors 请求
【发布时间】:2015-05-10 11:51:28
【问题描述】:

我有一个 ajax 请求,它向 spring 控制器发送一个帖子,其中有 response.sendRedirect(externalurl) 到外部 url。

问题是 externalurl 不支持 cors/jsonp。 但由于它是带有 cors 的 ajax 请求,因此设置了“origin”标头。 有什么方法可以删除原始标头并执行 response.sendredirect。

【问题讨论】:

    标签: ajax spring cors


    【解决方案1】:

    尝试在 sendRedirect 之前使用 response.reset()。我认为如果外部 url 不明确期望某些东西,它会起作用。

    【讨论】:

    • 您确定没有任何其他配置来设置这些标头吗?例如。某些过滤器可能属于 Spring 框架本身?
    • 来自 jsp 页面的 ajax 请求正在设置“origin”标头。弹簧侧什么都没有……没有过滤器……
    • 您遇到了什么错误,您是如何确定是由于原始标头引起的?
    【解决方案2】:

    我能够使用 spring Redirect 模型和 View 方法成功地做到这一点。 我停止使用 response.sendRedirect。

    ModelAndView model = new ModelAndView();
        model.setViewName("redirect:" + authURL);
        return model;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-27
      • 2020-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-07
      • 2014-12-05
      • 1970-01-01
      相关资源
      最近更新 更多