calling languge detection from angular app showing Blocked by CORS policy

sam 201 Reputation points
2021-07-15T08:24:54.953+00:00

Calling text detection azure container instance url from angular app getting below error.

Error: Access to XMLHttpRequest at 'http://myurl/text/analytics/v2.0/languages' from origin 'http://localhost:4200' 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.

114967-image.png
identifyLanguage(data: any) {

var payload = {  
  "documents": [  
    {  
      "id": "1",  
      "text":  "This is for testing"  
    }  
  ]  
}  

const httpOptions = {  
  headers: new HttpHeaders({  
    'Content-Type':  'application/json; charset=utf-8'  
    })  
  };  

return this.http.post<any>
('http://myurl/text/analytics/v2.0/languages',JSON.stringify(payload),httpOptions)
}

Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
2,362 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. romungi-MSFT 41,866 Reputation points Microsoft Employee
    2021-07-15T13:32:58.897+00:00

    @sam A very similar thread on SO details possible solutions for this problem with angular apps. I hope this can help.