-1

I'm quite new of using API and here.

I'm facing CORS prob.

Error is below .

Access to XMLHttpRequest at 'https://api-us.faceplusplus.com/facepp/v3/detect?api_key={0}&api_secret={1}&image_url={2}&return_attributes={3}' 
from origin 'http://localhost:3111' has been blocked by CORS policy:
Response to preflight request doesn't pass access control check: 
No 'Access-Control-Allow-Origin' header is present on the requested resource
;

And here is my code

        async submit(){
          let imgSrc = document.getElementById("photo").src        
          const self = this
          try{
            let headers = {headers:{"Access-Control-Allow-Origin":"*",}}
            console.log(headers)
            let response = await self.$axios.$post(CONSTANTS.API_URL,self.createParam(imgSrc),headers)
            console.log(response)
          }catch(error){
            console.log(error)
          }
        },

I could check this API works properly at Restlet Client on Google Chrome.

this is screen shot on Restlet Client

Help me somebody.

Kei
  • 21
  • 1
  • 7

2 Answers2

0

Header Access-Control-Allow-Origin is not the one in the ajax request nor in the ajax response. The error is telling you that the script is attempting to download a resource from an untrust origin.

The origin here is the one from where the script is downloaded. So the header Access-Control-Allow-Origin need to be set by your backend that serve you the script containing the submit.

mathk
  • 7,973
  • 6
  • 45
  • 74
  • Mr.mathk thx for answer . I didn't know server allow Access from localhost . I'll check it out. – Kei Jan 17 '19 at 02:53
0

Access-Control-Allow-Origin is set on the server, not on the client.

Are you sending your request from localhost and does the API accept calls from localhost?

More information about CORS: https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS

allard
  • 78
  • 1
  • 7