Iva*_*hev 11 c# restsharp access-token
IRestResponse
我有以下问题:
public async Task<CezanneToken> GetAccessToken()
{
var client = new RestClient(WebConfigurationManager.AppSettings["TokenUrl"]);
var request = new RestRequest();
request.Method = Method.Post;
request.AddHeader("cache-control", "no-cache");
request.AddHeader("content-type", "application/x-www-form-urlencoded");
request.AddParameter("application/x-www-form-urlencoded", "grant_type=client_credentials&client_id=" + WebConfigurationManager.AppSettings["ClientId"] + "&client_secret=" + WebConfigurationManager.AppSettings["ClientSecret"] + "", ParameterType.RequestBody);
IRestResponse response = await client.ExecuteAsync(request);
string serStatus = ((RestResponseBase)response).Content;
CezanneToken details = JsonConvert.DeserializeObject<CezanneToken>(serStatus);
string Token = details.access_token;
return details;
}
Run Code Online (Sandbox Code Playgroud)
IRestResponse
投掷
找不到类型或命名空间名称“IRestResponse”(您是否缺少 using 指令或程序集引用?)我无法使其工作。IntelliSense 建议使用
RestResponse
> 而不是IRestResponse
。
但当我去的时候,RestResponse
我得到Bad Request
了回应。
上面的代码示例是从 Visual Basic“翻译”而来的,但它在 VB 中运行得很好。我不知道问题是否来自Bad Request
使用RestResponse
,但我认为IRestResponse
就像在 VB 中一样需要。
我也见过有人使用IRestResponse
,但它对我不起作用。我有,using RestSharp;
但是我还需要其他东西吗?