使用 Windows.Web.Http.HttpClient 类 PATCH 异步请求

编程入门 行业动态 更新时间:2024-10-28 04:28:04
本文介绍了使用 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 异步请求

本文发布于:2023-10-07 01:35:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1468068.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Web   Windows   Http   PATCH   HttpClient

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!