HttpRequest returns nothing

Holzchopf

Moderator
Staff member
Joined
Jul 31, 2017
Location
Bern, Switzerland
When I run examples/mojo/mak/httprequest it runs fine. But when I change this line
Code:
get_req=New HttpRequest( "GET","https://httpbin.org/",Self )
to this:
Code:
get_req=New HttpRequest( "GET","https://holzchopf.ch/home.xml",Self )
It stops working. At least in the HTML5 target, in GLFW it keeps working.

What am I missing?
 

Martin

Administrator
Staff member
Joined
Jun 19, 2017
Location
Germany
HttpRequest for HTML5 only works when your app runs on the same server where you do the request to. So when you upload your app to holzchopf.ch it should work from there.

That's a limitation due to that sandbox security stuff...
 

Holzchopf

Moderator
Staff member
Joined
Jul 31, 2017
Location
Bern, Switzerland
Opera. On Win10.

When trying to reach holzchopf.ch, the js console says
Failed to load https://holzchopf.ch/home.xml: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:53401' is therefore not allowed access.
No such message for httpbin.org

Did a quick research. Because my server doesn't send a 'Access-Control-Allow-Origin' header the browser defaults it's value - which is blocking the response. So without access to the resource server (or more specifically it's config for access control), loading those resources won't work. Too bad =(

btw. httpbin.org's response header contains 'Access-Control-Allow-Origin: http://localhost:53401'


Conclusion: Everything works as it should. Which is bad for my because it's supposed not to work the way I wanted.
 

wick

Member
3rd Party Module Dev
Patreon Bronze
Joined
Jul 17, 2017
You might not have to have access to the server's config; I think you can just set the access-control-allow-origin header directly on the page you're trying to connect to. I ran into the same problem trying to talk to a php script but was able to fix it by adding this to the top:

header("access-control-allow-origin: *");

Dunno how to set headers in HTML, though.
 
Top Bottom