Page 1 of 1

What am I doing wrong?

Posted: Fri Dec 14, 2018 7:36 pm
by kpeters58
My very first foray into the world of Spiderbasic - my code below returns an "HTTPRequest(): Error" when CNN's web site is definitely up and reachable.....

Code: Select all

  Global Parameters.s = "", Url.s = "http://www.cnn.com", NewMap Headers.s()
 
  Procedure HttpGetEvent(Success, Result$, UserData)
    If Success
      Debug Result$
    Else
      Debug "HTTPRequest(): Error"
    EndIf
  EndProcedure

  HTTPRequest(#PB_HTTP_Get, Url, Parameters, @HttpGetEvent(), 0, Headers())

Re: What am I doing wrong?

Posted: Fri Dec 14, 2018 10:59 pm
by Paul
From the help file...

HTTPRequest(Type, URL$, Parameters, Callback [, UserData [, Headers()]])

URL$ : The URL to execute the request. Due to security constraints, it is only possible to execute a request on the same domain.

Re: What am I doing wrong?

Posted: Sat Dec 15, 2018 12:06 am
by kpeters58
Yup - that should have been it; but there's more....

I have my API server up and running and can execute GET requests from Postman and Insomnia with the same Basic Auth and URL - Spiderbasic errors out with "HTTPRequest(): Error", though.

Any suggestions?


Code: Select all

  Procedure HttpGetEvent(Success, Result$, UserData)
    Debug UserData
    Debug Result$
    If Success
      Debug Result$
    Else
      Debug "HTTPRequest(): Error"
    EndIf
  EndProcedure 
  
  Procedure AttemptLogin()
    Protected url.s = "http://127.0.0.1:8001/account", params.s = ""
    
    Debug "Login attempt"
    NewMap Headers$()
    Headers$("Authorization") = "Basic dGVzdDpwYXNzd29yZA=="  ; = 'test'/'password' combination
    HTTPRequest(#PB_HTTP_Get, url, params, @HttpGetEvent(), 0, Headers$())
  EndProcedure
  
  AttemptLogin()

Re: What am I doing wrong?

Posted: Sat Dec 15, 2018 10:11 am
by poshu
Doesn't change anything : It's still a CORS problem...

Re: What am I doing wrong?

Posted: Mon Dec 17, 2018 8:13 am
by Dirk Geppert
@kpeters58: for cross domain access, the response header from the web server must include the attribute: "Access-Control-Allow-Origin: *"