我已经查看了 http://restsharp.org/ 的代码,它非常出色。以下是不带asp.net core的RestSharp代码。
public GenericResponseObject<T> GetGeneric<T>(string operation, params KeyValuePair<string, string>[] nameValues) where T : class
{
RestClient client = new RestClient(_baseUrl)
{
Authenticator = new HttpBasicAuthenticator(_username, _password)
};
RestRequest request = new RestRequest(operation, Method.GET);
foreach (KeyValuePair<string, string> nameValue in nameValues)
{
request.AddQueryParameter(nameValue.Key, nameValue.Value);
}
IRestResponse<GenericResponseObject<T>> response = client.Execute<GenericResponseObject<T>>(request);
GenericResponseObject<T> responseObject = response.Data;
return responseObject;
}
}
这段代码对我非常有用。现在我想在asp.net core中实现相同的代码。
我能否获得一个示例,演示如何在asp.net core中使用RestSharp。我已经添加了依赖项RestSharp.NetCore": 105.2.3。