如何解决VB.Net CALL rest API使用request.AddBody
如何使用request.AddBody方法在 VB.Net中将主体参数添加到其余API请求?
下面是我在C#中的代码,但我想在 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<SampleResponse>(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");
}
}
如何在VB中添加以上代码,尤其是类中的request.AddBody内容?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。