BeWyched
asked on
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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
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
ASKER
I had to tweak your coding but your post pointed me in the right direction - it now works!!