'AddBody Post Request from c# in vb

using RestRequest from RestSharp to add a body in a Post request it is:

var request = new RestRequest("somePath", Method.Post)
request.AddBody(new { Something = somethingData});

Now my question is, how can I do this in visual basic .net, I have something like this, but it doesn't work:

Dim request As WebRequest = WebRequest.Create("somePath")
request.Method = "POST"

Dim byteData() As Byte = UTF8.Encoding.UTF8.GetBytes(data.ToString)

request.ContentLength = byteData.Length

Dim postStream As Stream = request.GetRequestStream()
postStream.Write(byteData, 0, byteData.Length)
postStream.Close()

Dim dataStream As Stream = request.GetResponse.GetResponseStream()

Dim sr As New StreamReader(dataStream)
Return sr.ReadToEnd

The solution I find to post using VB is by getting a stream to the request, and passing data, but it doesn't work.

Any help is welcome. Thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source