我已经发送了 PUT
请求并得到 NullReferenceException
在RestSharp.Portable
:
using (var client = new RestClient(new Uri(BaseUri)))
{
var oAuth1Authenticator = OAuth1Authenticator.ForAccessToken(
OAuthConsumerKey,
OAuthConsumerSecret,
oAuthToken",
oAuthSecret"
);
client.Authenticator = oAuth1Authenticator;
var request = new RestRequest(lastPartUri, httpMethod);
request.AddJsonBody(body);
IRestResponse response = await client.Execute(request);
return response.Content;
}
线路IRestResponse response = await client.Execute(request);
抛出异常。
OAuth 参数绝对不是 null
,都不是BaseUri
和lastPartUri
。 body
是 Dictionary<string, string>
并且也不为空。
POST
和GET
具有相同参数的请求工作得很好。
看起来问题出在RestSharp
图书馆。我怎样才能找到它?
这是堆栈跟踪:
at RestSharp.Portable.Authenticators.OAuth1Authenticator.<>c.<AddOAuthData>b__84_3(Parameter p)
at System.Linq.Enumerable.WhereListIterator`1.MoveNext()
at RestSharp.Portable.Authenticators.OAuth1Authenticator.AddOAuthData(IRestClient client, IRestRequest request, OAuthWorkflow workflow)
at RestSharp.Portable.Authenticators.OAuth1Authenticator.PreAuthenticate(IRestClient client, IRestRequest request, ICredentials credentials)
at RestSharp.Portable.RestClientBase.<ExecuteRequest>d__67.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at RestSharp.Portable.HttpClient.RestClient.<Execute>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Store.Helpers.MyBookApiConnector.<SendRequest>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Store.Services.DataService.<UpdateReview>d__80.MoveNext()
最佳答案
这确实是库中的一个错误。开发者已经修复。
关于c# - 我如何找到 RestSharp PUT 抛出异常的原因?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39036762/