Link to home
Create AccountLog in
.NET Programming

.NET Programming

--

Questions

--

Followers

Top Experts

Avatar of BeWyched
BeWyched

Convert cURL to VB.NET
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 vb.net to obtain an access token from an OAuth2 authorisation server. I'm normally reasonably competent handling HTTP requests in vb.net but I just can't get this to work. can anyone help please?

curl  -u  ID_Key:Secret_Key  https://targetURL.com  -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("https://targetURL.com?grant_type=client_credentials")

        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()
            Debug.Print(contents)
        End With


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

Many thanks.

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


ASKER CERTIFIED SOLUTION
Avatar of gr8gonzogr8gonzo🇺🇸

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

Avatar of BeWychedBeWyched

ASKER

Many thanks gr8gonzo.

I had to tweak your coding but your post pointed me in the right direction - it now works!!

Super-fast response!

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


Avatar of sqdperusqdperu🇺🇸

BeWyched ,

Would you mind sharing your code?  

I have the same question and would like to see how you did it in VB.net after tweaking the sample.

Thanks
.NET Programming

.NET Programming

--

Questions

--

Followers

Top Experts

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.