简体   繁体   English

如何在 twitter 上运行的 chrome 扩展中发出 POST 请求?

[英]How can I make a POST request in a chrome extension that runs on twitter?

Currently, I am running a content script whenever https://twitter.com/home loads.目前,每当https://twitter.com/home加载时,我都会运行一个内容脚本。 The content script makes a POST request to my own API server (hosted on AWS) in the content script, using Axios.内容脚本使用 Axios 在内容脚本中向我自己的 API 服务器(托管在 AWS 上)发出 POST 请求。 But I run into the following error:但我遇到以下错误:

Access to XMLHttpRequest at '${endpoint url}' from origin 'https://twitter.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

I've only just started building chrome extensions so I'm probably doing it completely wrong.我才刚刚开始构建 chrome 扩展,所以我可能做错了。 Please correct me and let me know how a feature like this could be implemented.请纠正我,让我知道如何实现这样的功能。

You have 2 options:您有 2 个选项:

  1. Configure your AWS server to provide the CORS policy by adding an Access-Control-Allow-Origin header for example.例如,通过添加Access-Control-Allow-Origin header 来配置您的 AWS 服务器以提供 CORS 策略。
  2. Do the request in your background script because CORS policy is not enforced there.在您的后台脚本中执行请求,因为 CORS 策略没有在那里强制执行。

Further reading can be found here .进一步阅读可以在这里找到

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM