Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
95
rated 0 times [  98] [ 3]  / answers: 1 / hits: 24875  / 7 Years ago, fri, june 30, 2017, 12:00:00

I need to do this call



axios.get(http://127.0.0.1/myapi/test.php).then((response) => {
})


If I do this call all is ok and HTTP method is GET, but if I change to this



var config = {
headers: {X-Id-Token: abc123abc123}
};
axios.get(http://127.0.0.1/myapi/test.php, config).then((response) => {
})


The HTTP method is OPTIONS and the call fails, why?



EDIT



I'm runnig reactjs project with node (localhost:3000) and I call php api on IIS (http://127.0.0.1/myapi)



SOLUTION



Axios client makes a ping request for to check if address is reachable.
So, the first call is in OPTIONS method, later calls are in GET.


More From » ajax

 Answers
12

good suggestion from Mayank Shukla, it's a CORS problem, I modified my web.config from this



<add name=Access-Control-Allow-Origin value=* />


to this



<add name=Access-Control-Allow-Origin value=http://localhost:3000 />

[#57256] Tuesday, June 27, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jazminuniquer

Total Points: 63
Total Questions: 121
Total Answers: 96

Location: Cambodia
Member since Thu, May 21, 2020
4 Years ago
;