最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

reactjs - Are there any CORS workaround without server side change in Javascript? - Stack Overflow

programmeradmin4浏览0评论

I am trying to access a publicily shared google drive video file from my react website , since google drive file is not a absolute downloadable file,I am trying to play google drive video with a Custom Player ,so before showing the video in the player , I need to extract absolute file url with an XHR request.But I cannot access googledrive with XHR beacause it will only get CORS errors.Is there a way to request other server domains from a client domain without any serverside changes?

I am trying to access a publicily shared google drive video file from my react website , since google drive file is not a absolute downloadable file,I am trying to play google drive video with a Custom Player ,so before showing the video in the player , I need to extract absolute file url with an XHR request.But I cannot access googledrive. with XHR beacause it will only get CORS errors.Is there a way to request other server domains from a client domain without any serverside changes?

Share Improve this question asked Jul 24, 2021 at 5:49 Lwin Moe HeinLwin Moe Hein 5091 gold badge5 silver badges13 bronze badges 3
  • 3 The only way to spoof a request origin is through server-side code. – Wais Kamal Commented Jul 24, 2021 at 5:51
  • 1 @WaisKamal - you don't have to spoof anything from a server since servers are not subject to CORS rules – Bravo Commented Jul 24, 2021 at 5:55
  • 1 @Bravo sometimes the same-origin policy is enforced by the server providing the content. In this case you have to spoof the origin. – Wais Kamal Commented Jul 24, 2021 at 5:57
Add a ment  | 

1 Answer 1

Reset to default 8

Short Answer

No. It's impossible to get around CORS without modifying server-side code.

Long Answer

CORS (Cross Origin Resource Sharing) is a browser's way of letting developers connect to external APIs from your website.

But that is an obvious security risk, not all APIs are meant to be public. To fix this risk, CORS only allows you to municate to servers that have CORS enabled.

Unless the owners of the server suddenly decide to enable CORS, you cannot make a request from your website to the server.

The only way

The only way to achieve your goal is to send the request from a server. When making requests from server to server, there is no CORS (it only exists on browsers).

You would have to create a server yourself, make the request there, and send the response to the client.

发布评论

评论列表(0)

  1. 暂无评论