NuxtN
Nuxt3y ago
2 replies
clownshark5503

$fetch with POST and same origin policy error

Hi everyone, I'm trying to make a POST request with $fetch to my backend(asp.net) but I consistently get this error message. Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://localhost:myport/myendpoint. (Reason: header ‘content-type’ is not allowed according to header ‘Access-Control-Allow-Headers’ from CORS preflight response).

GET requests to my backend works. My backend CORS set up also should be permitting that the frontend makes this request. I wonder if my frontend being http:localhost:port/etc... and my backend being https:localhost:someport/etc has something to do with it but idk.

Here's my function:
 async makeRes(){
 const h = useRequestHeaders([''])

 return await $fetch('https://localhost:port/myendpoint',{
        headers:{
          h
        },
        method: 'POST',
        body:{
          'message':  <my-data>,
          
        }
        
      })
}

Whats yalls opinion?
Was this page helpful?