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
Post
by kpeters58 » Fri Dec 14, 2018 7:36 pm
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())
Paul
Posts: 195 Joined: Wed Feb 26, 2014 6:46 pm
Location: Canada
Contact:
Post
by Paul » Fri Dec 14, 2018 10:59 pm
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
Post
by kpeters58 » Sat Dec 15, 2018 12:06 am
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
Post
by poshu » Sat Dec 15, 2018 10:11 am
Doesn't change anything : It's still a CORS problem...
Dirk Geppert
Posts: 282 Joined: Fri Sep 22, 2017 7:02 am
Post
by Dirk Geppert » Mon Dec 17, 2018 8:13 am
@kpeters58: for cross domain access, the response header from the web server must include the attribute: "Access-Control-Allow-Origin: *"