What am I doing wrong?

Just starting out? Need help? Post your questions and find answers here.
kpeters58
Posts: 19
Joined: Fri Dec 07, 2018 7:27 pm
Location: BC, Canada

What am I doing wrong?

Post 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())
User avatar
Paul
Posts: 195
Joined: Wed Feb 26, 2014 6:46 pm
Location: Canada
Contact:

Re: What am I doing wrong?

Post 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.
kpeters58
Posts: 19
Joined: Fri Dec 07, 2018 7:27 pm
Location: BC, Canada

Re: What am I doing wrong?

Post 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()
poshu
Posts: 96
Joined: Mon Feb 24, 2014 11:46 pm

Re: What am I doing wrong?

Post by poshu »

Doesn't change anything : It's still a CORS problem...
Dirk Geppert
Posts: 282
Joined: Fri Sep 22, 2017 7:02 am

Re: What am I doing wrong?

Post by Dirk Geppert »

@kpeters58: for cross domain access, the response header from the web server must include the attribute: "Access-Control-Allow-Origin: *"
Post Reply