我有以下方法,当运行时导致MissingMethodException方法(' System.Net.Http.HttpClientHandler.set_AutomaticDecompression' not found)
public async Task<TokenResponseModel> Login (string username, string password)
{
var tokenResponse = new TokenResponseModel ();
try {
var request = new RestRequest (Method.POST);
request.AddParameter ("username", username);
request.AddParameter ("password", password);
request.AddParameter ("grant_type", "password");
request.AddHeader ("Accept", "application/json");
using (var client = new RestClient (GetStringRequest ("Token"))) {
var json = await client.Execute<TokenResponseModel> (request);
tokenResponse = JsonConvert.DeserializeObject<TokenResponseModel> (json.Content);
}
return tokenResponse;
} catch (Exception e) {
Debug.WriteLine ("Exception thrown - {0}--{1}", e.Message, e.InnerException);
return tokenResponse;
}
}
我知道我可以使用ClientHandler设置AutomaticDecompression,但我似乎找到了将ClientHandler连接到RestClient的方法。有没有办法可以直接将ClientHandler连接到RestClient,还是RestSharp.Portable可以自行设置AutomaticDecompression?