0

I am aware there are many answers related to this question but since nothing seems to work I am posting here.

I have NuxtJS/Vuejs application within which users can provide the GitHub URL (mostly the URL will contain the XML/JSON files). After getting the URL, I want to make a request to the URL using the axios and obtain the data present within the URL.

When I try to make a request i get the following error:

Access to XMLHttpRequest at 'GitHub URL' from origin 'http://localhost:3000' has been blocked by CORS policy: The 'Access-Control-Allow-Origin' header contains multiple values 'Some GITHUB URL', but only one is allowed.

When I provide the same URL in the browser then I get the 302 status and obtain the raw JSON/XML data after redirection. I want to implement the same in my code.

If data is not found in the URL then obtain the redirection URL from the response and make another request with the new URL. But due to the CORS error and other error GET GIT HUB URL net::ERR_FAILED I am unable to get the response.

I tried many things mentioned on the website such as:

  1. Adding proxy as mentioned here: https://stackoverflow.com/a/55481649/7584240
  2. Adding a prefix to URL as mentioned here: https://stackoverflow.com/a/56781665/7584240
  3. Adding the condition to axios as mentioned here: https://stackoverflow.com/a/48293817/7584240

And many other things but nothing seems to work for me and getting the same error. Can someone please help me with this issue?

Following is the sample code I have (The code is part of VUEX Store actions):


export const actions = {
    obtainURLData ({ commit, state, dispatch, rootState }, inputURL) {
        axios
        .get(inputURL)
        .then((response) => {
            console.log('INSIDE RESPONSE')
            console.log(response)
            console.log(response.data)
            if (response.status === 200) {
            }
        })
        .catch((error) => {
            console.log('INSIDE ERROR')
            console.log(error)
            console.log(error.response)
            console.log(error.response.data.detail)
            console.log(error.response.status)
        })
    }
}
BATMAN_2008
  • 2,788
  • 3
  • 31
  • 98
  • Hi, can you check the values that you're sending in the network tab? (what are the multiple headers as the error tells you) – kissu Sep 24 '21 at 09:42
  • @kissu Sorry I missed your reply. In `Network` tab I am getting the response with status 302 and the `location` which has the `redirected URL` but I am unable to get that in my code. I want to get that `location URL` within my code so I can make another request to that URL and read the data from there. Any workaround or suggestion to make this work? – BATMAN_2008 Oct 01 '21 at 16:09

0 Answers0