React应用程序无法从Azure SQL后端获取数据(无法加载资源:NET :: ERR_CONNECTION_REFUSE)

发布于 2025-02-07 03:36:23 字数 991 浏览 1 评论 0原文

我在Azure上使用ASP.NET Core 5.0.17 App托管了React Spa,但无法从API获取数据。我还托管了Azure SQL Backend上的SQL数据库,并更改了Web应用程序上的连接字符串以匹配它。为什么React应用程序仍然无法获取数据?

无法加载资源:net :: err_connection_refused: https://freeimage.host/i/h7ii2f

garacyforecastController Api能够从硬座上的数据中获取addodeded array: https://freeimage.host/i/h7i91a

文件: https://freeimage.host/i/h7ioeg https://onboarding2.azurewebsites.2.azurewebsites.net/api/customers

Postman返回API的数据返回数据: https://freeimage.host/i/h7sssdb

I hosted a React SPA with ASP.NET Core 5.0.17 App on Azure but it is unable to fetch data from the API. I've also hosted the SQL database on Azure SQL backend and changed the connection strings on the Web App to match it. Why is the React App still unable to fetch data?

Failed to load resource: net::ERR_CONNECTION_REFUSED:
https://freeimage.host/i/h7iI2f

WeatherForecastcontroller API is able to fetch data from hardcoded array: https://freeimage.host/i/h7i91a

This is my Fetch API source URI saved in .env file: https://freeimage.host/i/h7iOEg
https://onboarding2.azurewebsites.net/api/customers

Postman is returning data from API: https://freeimage.host/i/h7ssDB

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

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

发布评论

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

评论(1

江城子 2025-02-14 03:36:23

这个问题很明显,应该是.env文件在水疗中没有生效。

请检查此博客。本文详细描述了如何配置和启用环境变量。

将环境添加到ASP.NET核心的react.js spa

This problem is obvious, it should be that .env file does not take effect in SPA.

Please check this blogs.This article describes in detail how to configure and enable environment variables.

Adding environments to ASP.NET Core with React.js SPA

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