不抛出错误的http客户端 [英] http clients that dont throw on error
本文介绍了不抛出错误的http客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找在收到HTTP错误(例如404)时不会抛出的c#HTTP客户端.这不仅仅是样式问题;它对于非2xx回复具有主体是完全有效的,但是如果在执行GetResponse()时HTTP堆栈抛出,我将无法理解它.
I am looking for c# HTTP client that doesn't throw when it gets an HTTP error (404 for example). This is not just a style issue; its perfectly valid for a non 2xx reply to have a body but I cant get at it if the HTTP stack throws when doing a GetResponse()
推荐答案
所有返回 Task< HttpResponseMessage>
的 System.Net.Http.HTTPClient
方法都执行 NOT 抛出任何HttpStatusCode.它们只会引发超时,取消或无法连接到网关的情况.
All the System.Net.Http.HTTPClient
methods that return Task<HttpResponseMessage>
do NOT throw on any HttpStatusCode. They only throw on timeouts, cancellations or inability to connect to a gateway.
这篇关于不抛出错误的http客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文