A 'CORS' error occurred while transmitting data from the client to the service. Therefore, "Access-Control-Allow-Origin" was added to the 'HTTP response header' to the IIS and to the WCF-Web.config.
However, the following error occurred.
test client_1.html:11 Fetch API cannot load origin: http://localhost:59755/StudentService.svc/
Ply_GetGamedata. URL scheme "origin" is not supported.
-MY client Code
function PostFetch() {
fetch('Origin: http://localhost:59755/StudentService.svc/Ply_GetGamedata', {
method: "POST",
headers: {
"Content-Type": "application/json",
},
mode: 'cors',
cache: 'no-cache',
credentials: 'same-origin',
body: JSON.stringify({
id: 11111111,
password: "A0"**strong text**
}),
})
.then((response) => response.json())
.then((data) => console.log(data));
}
-Web.config in My service Code
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
<add name="Access-Control-Allow-Methods" value="GET,POST,PUT,DELETE,OPTIONS" />
<add name="Access-Control-Allow-Credentials" value="true" />
</customHeaders>
If don't attach 'origin', this error will occur. Where should I put "origin"?
(http://localhost:59755/StudentService.svc/Ply_GetGamedata)
Access to XMLHttpRequest at 'localhost:59755/Service1.svc/Test' from origin 'null' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
how can it be done? Thanks all