本文介绍了使用 Windows.Web.Http.HttpClient 类 PATCH 异步请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要使用 Windows.Web.Http.HttpClient 类执行 PATCH 请求,但没有关于如何执行此操作的官方文档.我该怎么做?
I need to do a PATCH request with the Windows.Web.Http.HttpClient class and there is no official documentation on how to do it. How can I do this?
推荐答案我找到了如何使用之前的 System.Net.Http.HttpClient 执行自定义"PATCH 请求code> class 这里,然后摆弄直到我让它工作在 Windows.Web.Http.HttpClient 类中,像这样:
I found how to do a "custom" PATCH request with the previous System.Net.Http.HttpClient class here, and then fiddled with until I made it work in the Windows.Web.Http.HttpClient class, like so:
public async Task<HttpResponseMessage> PatchAsync(HttpClient client, Uri requestUri, IHttpContent iContent) { var method = new HttpMethod("PATCH"); var request = new HttpRequestMessage(method, requestUri) { Content = iContent }; HttpResponseMessage response = new HttpResponseMessage(); // In case you want to set a timeout //CancellationToken cancellationToken = new CancellationTokenSource(60).Token; try { response = await client.SendRequestAsync(request); // If you want to use the timeout you set //response = await client.SendRequestAsync(request).AsTask(cancellationToken); } catch(TaskCanceledException e) { Debug.WriteLine("ERROR: " + e.ToString()); } return response; }更多推荐
使用 Windows.Web.Http.HttpClient 类 PATCH 异步请求
发布评论