我正在构建一个 Url 并PUT
使用 Flurl 发出请求,如下所示:
using (var client = new Url("myurl"))
.ConfigureClient(c => c.HttpClientFactory = new CompressHttpClientFactory())
.WithCookie(new System.Net.Cookie("name", "value", "/", "domain"))
{
var content = new StringContent("json here", Encoding.UTF8, "application/json");
var response = await client.PutAsync(content)
}
但是我在调用时遇到了一个异常PutAsync
:
System.NullReferenceException 发生 HResult=0x80004003 消息=对象引用未设置为对象的实例。Source=Flurl.Http StackTrace:在 Flurl.Http.FlurlClient.ReadResponseCookies(HttpResponseMessage response) at Flurl.Http.FlurlClient.d__28.MoveNext() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime。 System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() 处的 CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)
我应该使用try / catch
并忽略异常吗?