CORS policy error in SPFX

Occasional Contributor


Error I receive in the browser:

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.

Any Suggestions

2 Replies




CORS error will appear,when you are trying to invoke the API which is not hosted in your domain.


If you can modify the  hosted API configuration,you can allow CORS on the API,otherwise you need to build some proxy to invoke the request.


Readymade proxy will be heroku one


There are some side effects to it  as well,like since this is hosted publicly ,you might experience slowness if heroku one takes time to process your request.


you can build your own custom proxy as well and host it in your organization.


I only need to Authenticate username and password from another site.
I am using SharePoint Framework POST API to do so. I use the funciton "this.context.httpClient.POST( postURL, HttpClient.configurations.v1, httpClientOptions)"

I have below mentioned headers and body

const body: string = JSON.stringify({
'username': value1,
'password': value2,
'options': value3,

const requestHeaders: Headers = new Headers();
requestHeaders.append('Content-type', 'application/json');
requestHeaders.append('Accept', 'application/json');
requestHeaders.append('Cache-Control', 'no-cache');

requestHeaders.append('User-Agent', 'PostmanRuntime/7.20.1');
requestHeaders.append('Postman-Token', 'xxxxxxxxxxxxxxxxxxxxxxxxxx');
requestHeaders.append('Host', '');
requestHeaders.append('Accept-Encoding', 'gzip, deflate');
requestHeaders.append('Content-Length', '161');
requestHeaders.append('Cookie', 'xxxxxx=xxxxxxxxxxxxxxxxxxxxx');
requestHeaders.append('Connection', 'keep-alive');