【发布时间】:2020-02-10 19:51:56
【问题描述】:
我需要编写一个可用于任何类对象的辅助方法。简而言之,我需要使 PostAsJsonAsync 方法通用。现在是这样的:
public HttpResponseMessage POSTRequest(StudentViewModel student)
{
using (var client = new System.Net.Http.HttpClient())
{
client.BaseAddress = new Uri(_BaseAddress);
var postTask = client.PostAsJsonAsync<StudentViewModel>("student", student);
postTask.Wait();
var result = postTask.Result;
return result;
}
}
如果我像上面那样使用它,我需要为其他视图模型对象的每个请求编写它。我怎样才能重写它,使它成为所有 POST 请求的通用方法?
【问题讨论】:
-
到目前为止你已经尝试过什么
标签: c# httprequest