I was using RestSharp which returns the server response status code in a property of type HttStatusCode
and I needed to check for a 422 response myself but the of course the type doesn’t include it. Fortunately I was still able to test using the following:
if(response.StatusCode == (HttpStatusCode)422)
{
// Do my stuff..
}
Related Contents:
- How do you set the Content-Type header for an HttpClient request?
- Setting Authorization Header of HttpClient
- Pass an array of integers to ASP.NET Web API?
- Best practice to return errors in ASP.NET Web API
- How do I make calls to a REST API using C#?
- How do I set a cookie on HttpClient’s HttpRequestMessage
- How to enable CORS in ASP.net Core WebAPI
- Deciding between HttpClient and WebClient [closed]
- Returning http status code from Web Api controller
- Throw HttpResponseException or return Request.CreateErrorResponse?
- How to POST using HTTPclient content type = application/x-www-form-urlencoded
- System.Net.WebException HTTP status code
- RestSharp JSON Parameter Posting
- System.Net.Http: missing from namespace? (using .net 4.5)
- RestSharp simple complete example [closed]
- How can I return a custom HTTP status code from a WCF REST method?
- Asp.Net WebApi2 Enable CORS not working with AspNet.WebApi.Cors 5.2.3
- No connection could be made because the target machine actively refused it 127.0.0.1:3446
- web-api POST body object always null
- How do you debug MVC 4 API routes?
- Download file with WebClient or HttpClient?
- How to send a Status Code 500 in ASP.Net and still write to the response?
- Universal Apps MessageBox: “The name ‘MessageBox’ does not exist in the current context”
- 404 error after adding Web API to an existing MVC Web Application
- What exactly is the difference between Web API and REST API in MVC?
- How to make a HTTP PUT request?
- JSON.NET DeserializeObject to List of Objects
- Could not find a base address that matches scheme https for the endpoint with binding WebHttpBinding. Registered base address schemes are [http]
- Deserializing a json string with restsharp
- Calling a rest api with username and password – how to
- Hide Status bar in Windows Phone 8.1 Universal Apps
- Authorization header is lost on redirect
- ServiceStack REST API and CORS
- C# How to set HttpClient Keep-Alive to false
- Why does Boolean.ToString output “True” and not “true”
- Iterate two Lists or Arrays with one ForEach statement in C#
- The instance of entity type cannot be tracked because another instance of this type with the same key is already being tracked
- Using AES encryption in C#
- Is [CallerMemberName] slow compared to alternatives when implementing INotifyPropertyChanged?
- Checking if an object is a number
- Get full query string in C# ASP.NET
- No OWIN authentication manager is associated with the request
- Convert JSON to DataTable
- Where is the NuGet package for Microsoft.WindowsAzure.ServiceRuntime?
- NUnit expected exceptions
- Erratic Invalid Viewstate issue in a .NET application
- Why does my nested HttpModule EndRequest event handler not fire?
- Using Exception.Data
- How to start ChromeDriver in headless mode
- What’s the difference between anonymous methods (C# 2.0) and lambda expressions (C# 3.0)? [duplicate]