【发布时间】:2018-01-16 14:55:12
【问题描述】:
我正在发布到返回 409 响应代码的 API 以及如下所示的响应正文:
{
"message": "Exception thrown.",
"errorDescription": "Object does not exist"
}
如何提取响应体并反序列化它?
我正在使用 HttpClient:
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("http://localhost:60129");
var model = new Inspection
{
CategoryId = 1,
InspectionId = 0,
Descriptor1 = "test descriptor 121212",
Name = "my inspection 1121212"
};
var serializer = new JavaScriptSerializer();
var json = serializer.Serialize(model);
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
var result = client.PostAsync("api/Inspections/UpdateInspection", stringContent);
var r = result.Result;
我似乎是一件很平常的事情,但我很难找到数据在我的结果中的位置。
【问题讨论】:
标签: c# asp.net-web-api http-post