Page 1 of 1

HTTP Request problems

Posted: Sat Nov 07, 2020 4:38 pm
by bhicketts
Hi,
I have a dummy text file on a webserver which I want to read with spiderbasic.
The file is at http://bhhomeweb.ddns.net/app6.txt
If I type this address into any browser I get the status 200 and the text content.
I can sent a Http Get command from Purebasic and get the correct status code and text content.
I tried with spiderbasic using the code below but it returns status code 0 and no data.

Code: Select all

Procedure HttpGetEvent(Success, Result$, UserData)
      Debug  Success
      Debug Result$
EndProcedure

HTTPRequest(#PB_HTTP_Post, "http://bhhomeweb.ddns.net/app6.txt", "", @HttpGetEvent())
Can you show me what I'm doing wrong please

Thanks

// Code-Tags added (Peter)

Re: HTTP Request problems

Posted: Sat Nov 07, 2020 11:19 pm
by Peter
If you open the developer console of your browser (usually with <F12>), you will see the following:
Access to XMLHttpRequest at 'http://bhhomeweb.ddns.net/app6.txt' from origin 'http://127.0.0.1:9080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
This means that your code must be executed at the same address as the address where your text file is located.

More informations: https://en.wikipedia.org/wiki/Cross-ori ... ce_sharing

And: https://enable-cors.org/server_apache.html

Re: HTTP Request problems

Posted: Sun Nov 08, 2020 8:32 am
by plouf
and to add to above

since as said browsers prevent loading anything outside the domain you are ruinning to.
if you are planing to add the script LATER to your web server, but want to test it from your home, you can add some of CORS disablers plugins/extensins exist both for chrome and firefox,
So you can test it in you.

its not for final distribution because by definition all user will have block it !

Re: HTTP Request problems

Posted: Sun Nov 08, 2020 11:56 am
by bhicketts
Thanks for your fast responses, I'm learning a lot of things fast from this forum.