Skip to content

serviceComb框架如何设置支持跨域? #1578

@whuxiari

Description

@whuxiari

业务需要支持跨域访问,而浏览器会在跨域发生前先发起试探的OPTIONS请求,服务端却响应“Method not Allowed”失败,最终导致请求失败。

OPTIONS前端请求:
image
响应体:
image

服务端已通过过滤器设置支持跨域如下:

    responseEx.setHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, ALLIANCE_DOMAIN);

    responseEx.setHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS, "true");

    responseEx.setHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS,
        "Content-Type,X-Requested-With,Access-Control,Referer,Sec-Fetch-Dest,User-Agent,Accept-Encoding,Cache-Control,Content-Length,Host,Origin");
    responseEx.setHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS, "POST,GET,OPTIONS,DELETE,PUT");
    responseEx.setHeader(HttpHeaders.ACCESS_CONTROL_MAX_AGE, "86400");

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions