CURL to Xojo URLConnection formatting

How would I translate this CURL command into a URLConnection command?
curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer b7d03a6947b217efb6f3ec3bd3504582" "https://api.digitalocean.com/v2/droplets?page=1&per_page=1"

I would think the final command would be:
URLConnection1.Send("GET", "https://api.digitalocean.com/v2/droplets?page=1&per_page=1"

And I assume before that command I would do:
URLConnection1.RequestHeader("Authorization") = "Bearer b7d03a6947b217efb6f3ec3bd3504582"
Does the “Bearer” word need to be in there or just the Token?

Do I also need:
URLConnection1.SetRequestContent("", "application/json")
Not sure if I’m passing any RequestContent in this example?

Or do I need additionally/instead of SetRequestContent:
URLConnection1.RequestHeader("Content-Type") = "application/json" ?

We could easily translate them into Xojo with our MBS Xojo CURL Plugin.

curl.SetOptionHTTPHeader for the headers like Content-Type and Authorization.

CURL from command line to Plugin

I usually save MBS for the “tough stuff” :slight_smile:
The rest of the time I’m here to learn by doing it the hard way!

There is no efficient way to handle curl with xojo that’s why Christian was mentioning mbs curl. Xojo leaks at that point a bit

Yes, “Bearer” is part of the header.

No.

I beg to differ.

2 Likes

Okay let’s make a competition: handle curl with xojo and with java. Guess what?

I don’t understand the question.

Not sure what you mean, however I think this specific CURL command can be easily translated.
If you disagree, can you please expand on why?

Thank you.

Just to clarify - I don’t need anything other than

URLConnection1.RequestHeader("Authorization") = "Bearer b7d03a6947b217efb6f3ec3bd3504582"
URLConnection1.Send("GET", "https://api.digitalocean.com/v2/droplets?page=1&per_page=1"

That should work.

1 Like

P.S. Using the libcurl to Xojo binding I linked to before, it would look something like this:

  Dim curl As New cURLClient
  Call curl.EasyItem.SetAuthMethods(CType(libcURL.CURLAUTH.BEARER, Integer))
  Call curl.SetOption(libcURL.Opts.XOAUTH2_BEARER, "b7d03a6947b217efb6f3ec3bd3504582")
  If curl.Get("https://api.digitalocean.com/v2/droplets?page=1&per_page=1") Then
    Dim result As String = curl.GetDownloadedData()
  End If

Thank you!