Is there a way to make a web request in C # that does not throw an exception in the 4xx and 5xx status codes?

I am using CouchDB as a data source for a C # web service.

Being RESTful, CouchDB passes a 404 status code when requesting a document that does not exist. The standard .NET web request wants to throw an exception, but (at least to me), reporting that the data source returned "no results" through the exception, is completely horrible; and this is the stink that I really don't want to hear in my code ...

Is there any replacement for WebRequest that I can use that will allow me to deal with status codes, as it seems to me?

EDIT: To clarify, due to the answers I have had so far: I don't want to hide the exception that causes WebRequest. I am looking for an alternative to the WebRequest standard that does not throw exceptions based on status codes, since the .NET interpretation of what constitutes an error does not comply with REST principles.

EDIT # 2 I really need a 3.5 compatible way to do this; sorry for not being specific at the beginning.

+3
source share
3 answers

The HttpClient library does not throw an exception after a request. See this for usage examples.

+2
source

, # CouchDB.

CouchDB CouchOne.

CouchDB #.

- HTTP. HTTTP , CouchDB API . . ( , WebRequest, -, .)

0

, . 404, , , , IIS " ".

-2

Source: https://habr.com/ru/post/1795440/


All Articles