PATCH使用Windows.Web.Http.HttpClient类进行异步请求 [英] PATCH Async requests with Windows.Web.Http.HttpClient class
本文介绍了PATCH使用Windows.Web.Http.HttpClient类进行异步请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要使用 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?
推荐答案
我找到了如何做自定义 PATCH
请求使用之前的 System.Net.Http.HttpClient
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;
}
这篇关于PATCH使用Windows.Web.Http.HttpClient类进行异步请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文