HTTP Request problems

Just starting out? Need help? Post your questions and find answers here.
bhicketts
Posts: 4
Joined: Tue Sep 03, 2019 2:11 pm

HTTP Request problems

Post 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)
User avatar
Peter
Posts: 1086
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: HTTP Request problems

Post 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
plouf
Posts: 194
Joined: Tue Feb 25, 2014 6:01 pm
Location: Athens,Greece

Re: HTTP Request problems

Post 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 !
Christos
bhicketts
Posts: 4
Joined: Tue Sep 03, 2019 2:11 pm

Re: HTTP Request problems

Post by bhicketts »

Thanks for your fast responses, I'm learning a lot of things fast from this forum.
Post Reply