Page 1 of 1

Can't fetch any data with HTTPRequest()

Posted: Tue Feb 16, 2016 8:23 am
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())

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

Posted: Tue Feb 16, 2016 8:49 am
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

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

Posted: Tue Feb 16, 2016 10:44 am
by spidernet
Thanks Peter,

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