Page 1 of 1

HTTPRequest

Posted: Sat Apr 08, 2023 11:25 am
by thanos
Hello.
I tried to run the HTTRequest example. SpiderBasic 2.40

Code: Select all

Procedure HttpGetEvent(Success, Result$, UserData)
  If Success
    Debug Result$
  Else
    Debug "HTTPRequest(): Error"
  EndIf
EndProcedure

; Get the content of this file, and display it in the debug window
;
HTTPRequest(#PB_HTTP_Get, "https://www.adouros.gr/projects/papertrade/pelates.php",  "", @HttpGetEvent())
;HTTPRequest(#PB_HTTP_Get, "https://www.adouros.gr/projects/papertrade/log_file.txt", "", @HttpGetEvent())
Both files, are existed and took results if I put the URL$ in a browse window.
I just received "HTTPRequest(): Error"
What am I missing?
Regards.

Re: HTTPRequest

Posted: Sat Apr 08, 2023 6:05 pm
by Peter
If you look at the output in the Developer Console of your browser, you will see the following:
Access to XMLHttpRequest at 'https://www.adouros.gr/projects/papertr ... 0976679930' 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.
I.e., for security reasons, access to a resource of another address has been denied.

If you own the web server that runs this php file, then you can allow CORS access. If not, then you only have the diversions via a component that is located on your web server.

Re: HTTPRequest

Posted: Tue Apr 11, 2023 7:39 pm
by thanos
Peter wrote: Sat Apr 08, 2023 6:05 pm If you look at the output in the Developer Console of your browser, you will see the following:
Access to XMLHttpRequest at 'https://www.adouros.gr/projects/papertr ... 0976679930' 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.
I.e., for security reasons, access to a resource of another address has been denied.

If you own the web server that runs this php file, then you can allow CORS access. If not, then you only have the diversions via a component that is located on your web server.
Thank you very much for your response!
I will check it.
For the record, I got the save error if I try to access the script from localhost which running xampp server. E.g.
localhost:8080/papertrade/pelates.php
Is it expected?

Re: HTTPRequest

Posted: Tue Apr 11, 2023 9:03 pm
by Paul
Your SpiderBasic code must be exported and run from the same server as your script.
If you are running your code from the IDE you will have the same problem.

Re: HTTPRequest

Posted: Wed Apr 12, 2023 8:30 pm
by thanos
Paul wrote: Tue Apr 11, 2023 9:03 pm Your SpiderBasic code must be exported and run from the same server as your script.
If you are running your code from the IDE you will have the same problem.
Thanks Paul.
I run the code, in both cases, from the IDE
I will try to export it
Regards

Re: HTTPRequest

Posted: Thu Apr 13, 2023 8:50 am
by plouf
if your you want to TEST on your computer install a CORS plugins to allow it
-> viewtopic.php?f=6&t=2186&p=8235#p8235

offcourse when finished both script and server must be match for security reasons, but these plugins help development a lot..