I
I
Ily4farmer2021-08-25 21:06:39
CORS
Ily4farmer, 2021-08-25 21:06:39

Why is the Axios get request not working?

There is a server address to which requests should be sent: http://tmgwebtest.azurewebsites.net/api/textstrings/{id }, where {id} is the string ID.

The row ID is an integer and can take values ​​in the range from 1 to 20 (the values ​​"005", "05" and "5" are equivalent).

A GET request to this address should return JSON with the following structure {"text":"Some text here."} (the text field contains the search string).

To authenticate with the server, add the "TMG-Api-Key" header with the value "0J/RgNC40LLQtdGC0LjQutC4IQ==" to the request.

Here is my code

async function fetchApi() {
    const id = 15
    const url = `http://tmgwebtest.azurewebsites.net/api/textstrings/${id}`
    
    await axios.get(
      url,
      {headers: {
          "TMG-Api-Key" : "0J/RgNC40LLQtdGC0LjQutC4IQ=="
        }
      }
    )
    .then((response) => {
        const respons = response.data;
        console.log(respons);
        
      },
      (error) => {
        console.log(error);
      }
    );
  }


But I get the following error:
Access to XMLHttpRequest at ' tmgwebtest.azurewebsites.net/api/textstrings/15 ' from origin ' localhost:3000 ' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request.

How to fix CORS issue?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
veryoriginalnickname, 2021-08-25
@veryoriginalnickname

https://stackoverflow.com/questions/42168773/how-t...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question