CORS request not working in Safari

后端 未结 13 1467
忘掉有多难
忘掉有多难 2020-11-27 06:04

I am making a CORS xhr request. This works fine in chrome, however when I run in safari I get an \'Can not load ---- access not allowed by Access-control-allow-origin\'.

13条回答
  •  一生所求
    2020-11-27 06:37

    Im not sure if anyone else will have this problem but I was making a request to a URL like:

    https://api.website.com/api/v1/users/auth0|5ef7502019360a7/

    The | (pipe) character in the URL was causing a strange issue with Safari because it was not being URL Encoded correctly.

    In my Javascript I simply replaced my old url:

    const url = "https://api.website.com/api/v1/user/auth0|5ef27593603a7";

    with

    const url = "https://api.website.com/api/v1/user/auth0|5ef27593603a7".replace("|", "%7C");

    %7C is the correct URL encoding for the | (pipe) character.

    Hope this helps someone!

提交回复
热议问题