question

sanm-7576 avatar image
0 Votes"
sanm-7576 asked romungi-MSFT answered

calling languge detection from angular app showing Blocked by CORS policy


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-cognitive-servicesazure-language-understanding
image.png (23.0 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

romungi-MSFT avatar image
0 Votes"
romungi-MSFT answered

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


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks. I was able to solve it by adding proxy config in Angular CLI

1 Vote 1 ·