1、在WPF项目中添加Nuget包,搜索RestSharp安装
2、新建Service文件夹,新建基础通用请求类BaseRequest.cs
public class BaseRequest
{
public Method Method { get; set; }
public string Route { get; set; }
public string ContenType { get; set; } = "application/json";
public string Parameter { get; set; }
}
3、在WPFProjectShared项目下新增类WebApiResponse.cs接收api返回信息
public class WebApiResponse
{
public string Message { get; set; }
public bool Status { get; set; }
public object Result { get; set; }
}
public class WebApiResponse<T>
{
public string Message { get; set; }
public bool Status { get; set; }
public T Result { get; set; }
}
4、添加httpclient请求帮助类