How do I add body parameters to a rest API request in <a href="https://hkrtrainings.com/vb-net-training"></a>VB.Net using request.AddBody method ? Below is my code in c#, but I want in VB.Net
RestClient client = new RestClient("URL of API service"); RestRequest request = new RestRequest("/MethodName", Method.POST); request.AddHeader("Accept", "application/json"); request.RequestFormat = DataFormat.Json; request.AddBody(new SampleClass { Property1 = Guid.NewGuid().ToString(), Property2 = "", Property3 = 123 }); if (response.StatusCode == System.Net.HttpStatusCode.OK) { //Deserialize JSON content string to object SampleResponse responseObj = JsonConvert.DeserializeObject(response.Content); if (responseObj == null) { throw new Exception("Error msg"); } if (responseObj.ResultList != null) { rVal = responseObj.ResultList.ToList(); } else { throw new exception("Error in API"); } }
How to add the above code in VB, especially the request.AddBody content from a class ?