June-28th-2021, 07:41 AM
Dear Armin,
>you agree that a standard web browser you are using to access the netPI via netPI's web pages works well, or?
I expect the above.
I'm not an expert for html & JavaScript so that I am not 100% sure my code is correct.
Attachments:
- index_xml.html & app_xml.js: this is a sample code for rest api by function 'XMLHttpRequest'.
- index_fetch.html & app_fetch.js: this is a sample code for rest api by function 'fetch'.
- nodered_flows_test_purpose.json: this is a Node-RED flow
I found the following description in a Japanese local site:
"I think that recent Chrome does not allow access to local files through httpd"
Therefore, the REST API is called on Node-RED just as a trial.
All of the above codes output the following errors to 'Console' tab of DevTools.
- Access to fetch at 'https://netpi1/login' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
- POST https://192.168.3.56/login net::ERR_FAILED
- Uncaught (in promise) TypeError: Failed to fetch
Have you ever call REST API to netPI from an html?
As far as I searched in Internet contents, the server side must include 'Access-Control-Allow-Credentials: true' to be accessed from a client.
Because the above error seems to output by this reason???
Thank you very much for your support.
Best regards,
>you agree that a standard web browser you are using to access the netPI via netPI's web pages works well, or?
I expect the above.
I'm not an expert for html & JavaScript so that I am not 100% sure my code is correct.
Attachments:
- index_xml.html & app_xml.js: this is a sample code for rest api by function 'XMLHttpRequest'.
- index_fetch.html & app_fetch.js: this is a sample code for rest api by function 'fetch'.
- nodered_flows_test_purpose.json: this is a Node-RED flow
I found the following description in a Japanese local site:
"I think that recent Chrome does not allow access to local files through httpd"
Therefore, the REST API is called on Node-RED just as a trial.
All of the above codes output the following errors to 'Console' tab of DevTools.
- Access to fetch at 'https://netpi1/login' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
- POST https://192.168.3.56/login net::ERR_FAILED
- Uncaught (in promise) TypeError: Failed to fetch
Have you ever call REST API to netPI from an html?
As far as I searched in Internet contents, the server side must include 'Access-Control-Allow-Credentials: true' to be accessed from a client.
Because the above error seems to output by this reason???
Thank you very much for your support.
Best regards,