Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at

motorcb
Member | 548
+
0
-

Hello,
I have simple API in Nette. That is OK.
When I want to call the API from React, is there Error: Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://xxx.com/api/v1/users. (Reason: CORS request did not succeed). Status code: (null).

How to fix it?
Thanx

David Grudl
Nette Core | 7790
+
-3
-

Do you know Google?

motorcb
Member | 548
+
+1
-

David Grudl wrote:

Do you know Google?

I can :-) But I don't know how to write it in Nette …

	header("Access-Control-Allow-Origin: *");
	header("Access-Control-Allow-Methods: PUT, GET, POST");
	header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
dakur
Member | 363
+
+1
-

I'd say something like $this->getHttpResponse()->addHeader('Access-Control-Allow-Origin, '*') in presenter..

See Response object for more on working with headers.

Last edited by dakur (2022-09-08 08:51)

David Grudl
Nette Core | 7790
+
0
-

motorcb wrote:

I can :-) But I don't know how to write it in Nette …

https://www.google.com/search?…

motorcb
Member | 548
+
0
-

Thanks guys