Flutter Web访问URL图像CORS策略

发布于 2025-02-02 14:03:34 字数 491 浏览 1 评论 0原文

在我试图显示网络映像时,在我的Flutter网络中,我会遇到CORS错误。 从'https://my-network-image-url.jpg'来访问xmlhttprequest'froment'http:// localhost:63785'已被CORS策略阻止:no'Access-Control-allow-Origin'Header存在在请求的资源上。

它在我的Android/iOS移动应用程序中正常工作。

我已经在后端PHP API中提取了同一问题。 当时,添加PHP文件中的标头解决了问题。

header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: X-Requested-With,content-type");

我很困惑如何在图像获取请求中添加标头。

对不起,如果我再次问同样的问题。 但是我找不到适当的解决方案。

提前致谢。

In my flutter web when I'm trying to show network image, I'm getting an error of CORS.
Access to XMLHttpRequest at 'https://my-network-image-url.jpg' from origin 'http://localhost:63785' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Its working properly in my Android/iOS Mobile Apps.

I already fetch same issue in my backend php api.
At that time adding headers in php file solve the issue.

header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: X-Requested-With,content-type");

I'm confuse how to add header in image get request.

Sorry If I'm asking same question again.
But I could not find proper solution for this.

Thanks in Advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忆梦 2025-02-09 14:03:34

您可以从任何其他端点模拟允许所有交叉起源的呼叫,就像我使用以下内容一样,

String allowCORSEndPoint = "https://api.allorigins.win/raw?url=";

在呼叫时,您可以使用这样的AA变量,

import 'dart:html' as html;

http.Response response = await http.get(
  Uri.parse(allowCORSEndPoint + url),
);

You can mock the calls from any other endpoint which allows all cross origins like I have used the following,

String allowCORSEndPoint = "https://api.allorigins.win/raw?url=";

And while making a call you can use a a variable like this,

import 'dart:html' as html;

http.Response response = await http.get(
  Uri.parse(allowCORSEndPoint + url),
);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文