Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
326 views
in Technique[技术] by (71.8m points)

javascript - 我得到了网络响应,但是CORS不允许它进入(I'm getting the network response, but CORS is not allowing it to enter)

I'm doing an API get request via axios to an Exchange Rates API

(我正在通过axios向汇率API进行API获取请求)

axios.get('https://api.exchangerate-api.com/v4/latest/USD').then(res=>console.log('res',res)).catch(err => console.log('err',err))

And I'm getting the correct answer in the network

(而且我在网络中得到正确的答案) API请求的响应

But this is what shows on in my console for de ERR of the get request

(但这就是在控制台中显示的get请求的ERR错误) 安慰

I've researched that CORS message and all they say is, that you have to configure your server to accept the authorization header, but thats not an API to my server, it's a third party's server

(我已经研究了CORS消息,它们的意思是,您必须将服务器配置为接受授权标头,但这不是我的服务器的API,而是第三方的服务器)

What can I do?

(我能做什么?)

UPDATE

(更新)

I changed from "axios" from js "fetch" and it worked!

(我从js“ fetch”的“ axios”更改了,它起作用了!)

I think maybe it was a default axios configuration that was causing the problem

(我认为可能是导致问题的默认axios配置)

  ask by Sven Brodersen translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It can't be done in a browser application(cross is only for browsers).

(无法在浏览器应用程序中完成(十字仅适用于浏览器)。)

It is a 3rd party so the only way to send request is by not having an origin =>> Have a server(nodejs application) sending the request in there and returning the response.

(这是第三方,因此发送请求的唯一方法是没有原始地址= >>,让服务器(nodejs应用程序)在那里发送请求并返回响应。)

You send a request to your server => server returns the response from the corss blocked => done

(您向服务器发送请求=>服务器从corss阻止返回响应 =>完成)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...