Answer the question
In order to leave comments, you need to log in
How to ignore an error when the server response is different from 200?
A request is made to the server, which returns a 401 code, which is normal behavior. How to make it ignore that the code is different from 200? If you catch in try catch, then the answer is not returned, it is null.
var req = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse res;
try {
res = (HttpWebResponse)req.GetResponse();
// Сервер возвращает код 401
}
catch {
// Здесь res = null
}
Answer the question
In order to leave comments, you need to log in
I found the solution myself, it turns out that the error is transmitted and the server response
var req = WebRequest.Create(url);
WebResponse res;
try {
res = req.GetResponse();
}
catch(WebException ex) {
res = ex.Response;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question