.NET Programming
--
Questions
--
Followers
Top Experts
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_credent ials'
My coding is:
Dim credstring As String = "ID_Key:Secret_Key"
Dim authstring As String = Convert.ToBase64String(Enc oding.UTF8 .GetBytes( credstring ))
Dim webrequest As WebRequest = webrequest.Create("https://targetURL.com?grant_type=client_credentials")
With webrequest
.Headers.Add("Authorizatio n", "BASIC " & authstring)
Dim webresponse As HttpWebResponse = .GetResponse() '
Dim stream As System.IO.Stream = webresponse.GetResponseStr eam()
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.
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_credent
My coding is:
Dim credstring As String = "ID_Key:Secret_Key"
Dim authstring As String = Convert.ToBase64String(Enc
Dim webrequest As WebRequest = webrequest.Create("https://targetURL.com?grant_type=client_credentials")
With webrequest
.Headers.Add("Authorizatio
Dim webresponse As HttpWebResponse = .GetResponse() '
Dim stream As System.IO.Stream = webresponse.GetResponseStr
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
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Many thanks gr8gonzo.
I had to tweak your coding but your post pointed me in the right direction - it now works!!
I had to tweak your coding but your post pointed me in the right direction - it now works!!
Super-fast response!
Tutorial and download source code Curl with VB.net:
http://laptrinhvb.net/bai-viet/chuyen-de-vb-net/Lay-thong-tin-chi-tiet-website-(file-get-content-hay-CURL)-trong-Visual-Basic---NET---Tim-kiem-thong-tin-doanh-nghiep-qua-ma-so-thue/dd9028e2ebba0083.html
http://laptrinhvb.net/bai-viet/chuyen-de-vb-net/Lay-thong-tin-chi-tiet-website-(file-get-content-hay-CURL)-trong-Visual-Basic---NET---Tim-kiem-thong-tin-doanh-nghiep-qua-ma-so-thue/dd9028e2ebba0083.html






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
.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.