Can't fetch any data with HTTPRequest()

Just starting out? Need help? Post your questions and find answers here.
spidernet
Posts: 72
Joined: Tue Feb 02, 2016 3:50 pm

Can't fetch any data with HTTPRequest()

Post by spidernet »

Hello,

This sounds very trivial, but I can't get any data out from the web server with HTTPRequest().
The web server running on localhost port 80. It receives the HTTP request and respond to it,
but when the SB application receives data it always return error.
I checked with Wireshark that HTTP headers are Ok, everything seems fine but no success.

HTTPRequest() also adds extra parameter "?_=1455609277339" to every request (random number),
I guess it needs that ID number from the web server in some header but not sure as not mentioned
in the documentation.

Is there something I missed?

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, "http://127.0.0.1/test.txt", "", @HttpGetEvent())
User avatar
Peter
Posts: 1197
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: Can't fetch any data with HTTPRequest()

Post by Peter »

Hello spidernet,

i guess when you open the developer console of your browser (in most cases by pressing <F12>), you can see something like that:
Chrome-Console wrote:XMLHttpRequest cannot load http://127.0.0.1/test.txt?_=1455612221384. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:9080' is therefore not allowed access.
(see also: http://forums.spiderbasic.com/viewtopic ... 1715#p1715)
spidernet wrote:HTTPRequest() also adds extra parameter "?_=1455609277339" to every request
this is a dummy-parameter to avoid caching problems.

Greetings ... Peter
spidernet
Posts: 72
Joined: Tue Feb 02, 2016 3:50 pm

Re: Can't fetch any data with HTTPRequest()

Post by spidernet »

Thanks Peter,

I added "Access-Control-Allow-Origin: *" header to the HTTP response packet on the server side and now it works! :)
Post Reply