I have below in wcf webconfig
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type, Accept" />
<add name="Access-Control-Allow-Methods" value="POST,GET,OPTIONS" />
<add name="Access-Control-Max-Age" value="1728000"/>
</customHeaders>
</httpProtocol>
service
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "getItem", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
[Description("Fetch item from database.")]
Angular 6 calling
this.http.post('http://localhost:49823/service.svc/getItem?authkey=key',
{
json data
}
).subscribe(data => {console.log(data) },err => {
console.log(err);
});
Interceptor
request = request.clone({
setHeaders: {
'Content-Type': 'application/json'
}
});
It throws error
Access to XMLHttpRequest at 'http://localhost:49823/service.svc/getitem?authkey=key5' from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
WCF service running on 49823 and angular 6 running on 4200.
Couldn't figure what is causing issue as already enable cors in wcf.
This is working fine in POSTMAN