When I replace the URL with www.example.com, it works and the content can be loaded.
I also tried it with various URL’s for different JSON’s from the Web, but it didn’t work too.
try this one, I am using this to communicate via https with Nextcloud API (Here: the News App). Strongly suggest to use Paw if you deal with JSONs. Normally UserIDs etc shouldn’t be send in the URL. The URL.Text from below is something like: https://host/index.php/apps/news/api/v1-2
dim socket1 As new HTTPSecureSocket
dim Credentials as string = Base64Encode("username and/or password and/or hash")
dim data As String
socket1.Secure = True
// Haeder with Credentials
socket1.SetRequestHeader("Accept", "application/json")
socket1.SetRequestHeader("Content-Type", "application/json; charset=utf-8")
socket1.SetRequestHeader("Authorization", "Basic " + Credentials)
data = socket1.SendRequest("GET", TheURL.Text + "/feeds", 120)
Thank you for the response, Greg.
Yes, I made a breakpoint at result = DefineEncoding(result, Encodings.UTF8) and found out that the variable result is empty.
Credentials shouldn’t be send over in URLs because they are stored everywhere even if send over https. Something like “http://teamwork.companyname.com/time/total.json?userId=111111” is evil! Maybe a reason why your script doesn’t work in the net with other JSON APIs?
Tomas, lets focus on why his script isn’t working instead of the security implications of his implementation. You’re only confusing matters with all this extra info.
Ricardo, when you hit that’s breakpoint, click on the sock variable in the debugger and see what the httpstatuscode value is.
To help debugging as previously mentioned I make heavy use of PAW so I can see it all work outside of the Xojo environment. I’ve also used PostMan, a Chrome plugin too (freebie). Once I know my RESTful parameters all work I then plugin to Xojo. Cures most ills
The _httpStatusCode is 401 (teamwork.companyname.com)
But when I replace the URL with http://httpbin.org/get it works.
I also tested it with https://api.guildwars2.com/, but it didn’t work.
401 means Not Authorized. You should look and see if that URL requires a username and password from a browser. If so, you’ll need to subclass the socket and implement the AuthorizationRequired event.
[quote=327089:@Greg O’Lone]
401 means Not Authorized. You should look and see if that URL requires a username and password from a browser. If so, you’ll need to subclass the socket and implement the AuthorizationRequired event.[/quote]