我不明白为什么会这样。我的代码使用webclient.uploadvaluesAsync()调用了一些Rest服务。多数情况下,这项工作有效,但是,偶尔会出现“对象未设置为实例”的nullexception。谁能帮忙吗?
try
{
using (var wb = new WebClient())
{
var data = new NameValueCollection();
data.Add("client_assertion",tokenStr);
data.Add("client_assertion_type", HttpUtility.HtmlEncode("urn:ietf:params:oauth:client-assertion-type:jwt-bearer"));
data.Add("code", code);
data.Add("grant_type", "authorization_code");
byte[] rspStrn = new byte[0];
rspStrn = await wb.UploadValuesTaskAsync($"{IdpUrl}api/openid_connect/token", "POST", data);
var responseString = Encoding.ASCII.GetString(rspStrn);
dynamic tokenResponse = JObject.Parse(responseString);
responseString, false);
return tokenResponse;
}
}
catch (WebException ex)
{
string responseText;
using (var reader = new StreamReader(ex.Response.GetResponseStream()))
{
responseText = reader.ReadToEnd();
}
log.Info("GetToken method webexception: " + ex);
throw new WebException("json exception: " + responseText);
}
catch (ArgumentNullException ex)
{