简体   繁体   English

如何在不通过浏览器的情况下从 React 调用 REST API

[英]How do make REST API call from React without passing through browser

I am making a REST API call from my React application and am running into the following problem:我正在从我的 React 应用程序调用 REST API 并遇到以下问题:

Access to XMLHttpRequest at '[API LOCATION]' from origin '[APPLICATION LOCATION]' 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.

How can I make the REST API call from my react client without the browser interfering?如何在没有浏览器干扰的情况下从我的反应客户端进行 REST API 调用? Where do I move the code?我在哪里移动代码?

I have solved this by calling a Google Firebase function (see https://firebase.google.com/docs/functions ) from my React client.我已经通过从我的 React 客户端调用 Google Firebase function(参见https://firebase.google.com/docs/functions )解决了这个问题。 The Firebase function makes the REST API call and then returns the result back to the React client. Firebase function 使 REST ZDB974238714CA8DE634A7CE1D08 调用返回到 React 客户端然后返回结果。

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

相关问题 如何创建 React 链接以通过单击处理程序进行 API 调用 - How to create a React Link to make API call through click handler React / Redux:从浏览器获取数据后如何调用API? - React/Redux: how to call an API after getting data from the browser? 如何在我的反应本机应用程序中通过 api 制作 paytm 的付款链接而不添加服务器 - How to make a Payment link of paytm through api in my react native app without adding a server 如何在NodeJs中做Web服务器以对API REST进行REST调用? - How to do a Web Server in NodeJs that makes a REST call to API REST? 如何从 REST API 调用中保存 PDF - How to save a PDF from an REST API call 如何使用节点 js 从 Microsoft Bot for Teams 进行 REST API 调用? - How to make a REST API call from Microsoft Bot for Teams using node js? 来自 REACT APP 的 Rest API 调用总是返回 isLoaded: false - Rest API call from REACT APP always return isLoaded: false 在反应中将 API 调用上的数据从父容器传递到子容器 - Passing data on an API call from parent to child container in react 如何使用Angualr.js进行REST调用而不重定向页面 - How to make a REST call without redirecting page using angualrjs 如何在 rest api 调用中构造 json 并使其同步 - how to structure json in rest api call and make it synchronous
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM