Search code examples
flutterapidarttoken

why Flutter throw this Access-Control-Allow-Origin: error while generating api token


When I send request to api, it throws the following error. can any one help what is wrong?

HTTP/1.1 404 Not Found
Cache-Control: private
Server: Microsoft-IIS/8.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: X-Requested-With, Content-Type, Origin, Authorization, Accept, Accept-Encoding
Access-Control-Allow-Methods: POST,GET,OPTIONS

I use this code to generate.

POST /login?format={format} 
    Host: authservice.priaid.ch
    Authorization: Bearer {"api_key"}:{"hashed_credentials"}

Solution

  • A 404 http statuscode means the endpoint you're requesting doesn't exist on host, so it's likely either:

    • The wrong host
    • the endpoint actually doesn't exist
    • a typo

    Make sure you read the documentation of the API you're using (if it exists) and check anything you might be missing.