troubleshooting Question

Convert cURL to VB.NET

Avatar of BeWyched
BeWyched asked on
Programming.NET ProgrammingVisual Basic.NET
5 Comments1 Solution3826 ViewsLast Modified:
Not sure what happened there - I thought I'd submitted this but its disappeared - so sorry if my question is duplicated!

Anyway, I need to convert the following cURL command to to obtain an access token from an OAuth2 authorisation server. I'm normally reasonably competent handling HTTP requests in but I just can't get this to work. can anyone help please?

curl  -u  ID_Key:Secret_Key  -d  'grant_type=client_credentials'

My coding is:

        Dim credstring As String = "ID_Key:Secret_Key"
        Dim authstring As String = Convert.ToBase64String(Encoding.UTF8.GetBytes(credstring))

        Dim webrequest As WebRequest = webrequest.Create("")

        With webrequest
            .Headers.Add("Authorization", "BASIC " & authstring)

            Dim webresponse As HttpWebResponse = .GetResponse() '

            Dim stream As System.IO.Stream = webresponse.GetResponseStream()
            Dim reader As New StreamReader(stream, Encoding.UTF8)
            Dim contents As String = reader.ReadToEnd()
        End With

Obviously the ID, Key and URL will be the real thing.

Many thanks.

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros