Hi have the following cURL command that I would like to convert to VB.NET or C#.
curl https://api.box.com/2.0/users \-H "Authorization: Bearer ACCESS_TOKEN" \ -d '{"login": "eddard@company.com", "name": "Ned Stark"}' \ -X POST
I've tried the following in VB.NET:
Dim url As String = "https://api.box.com/2.0/users"
Dim wrq = CType(Net.WebRequest.Create(url), HttpWebRequest)
Dim postString As String = "login=eddard@company.com&name=Ned Stark"
wrq.Headers.Add("Authorization: Bearer " & o2ses.AccessToken)
wrq.Method = "POST"
wrq.ContentType = "application/x-www-form-urlencoded"
wrq.ContentLength = postString.Length
Dim wrqWriter As New StreamWriter(wrq.GetRequestStream())
wrqWriter.Write(postString)
wrqWriter.Close()
Dim responseReader As New StreamReader(wrq.GetResponse().GetResponseStream())
Dim responseData As String = responseReader.ReadToEnd()
I am a newb to cURL and to using HttpWebRequest in .NET, but have converted cURL commands to .NET before (thanks to this site :)), but none with the -d option in them, so I'm kind of lost. It keeps returning error 400 (bad request) when the line below is executed.
Dim responseReader As New StreamReader(wrq.GetResponse().GetResponseStream())
I think it has to do with what data I am sending (i.e. it's not getting the proper 'login' and 'name' parameters it needs).
Any help is appreciated. I can try to provide more information if needed. As mentioned, I'm a newb to this, so I'll try my best.
Thanks!