diff --git a/src/RestSharp/RestClient.Serialization.cs b/src/RestSharp/RestClient.Serialization.cs index 658e53091..5e3005973 100644 --- a/src/RestSharp/RestClient.Serialization.cs +++ b/src/RestSharp/RestClient.Serialization.cs @@ -55,10 +55,10 @@ internal RestResponse Deserialize(RestRequest request, RestResponse raw) { // to a transport or framework exception. HTTP errors should attempt to // be deserialized if (response.Content != null) { - var handler = GetContentDeserializer(raw, request.RequestFormat); - // Only continue if there is a handler defined else there is no way to deserialize the data. // This can happen when a request returns for example a 404 page instead of the requested JSON/XML resource + var handler = GetContentDeserializer(raw, request.RequestFormat); + if (handler is IXmlDeserializer xml && request is RestXmlRequest xmlRequest) { if (xmlRequest.XmlNamespace.IsNotEmpty()) xml.Namespace = xmlRequest.XmlNamespace!; diff --git a/src/RestSharp/RestClientExtensions.Json.cs b/src/RestSharp/RestClientExtensions.Json.cs index 681245f5d..6dd7b8dee 100644 --- a/src/RestSharp/RestClientExtensions.Json.cs +++ b/src/RestSharp/RestClientExtensions.Json.cs @@ -66,7 +66,7 @@ public static partial class RestClientExtensions { TRequest request, CancellationToken cancellationToken = default ) where TRequest : class { - var restRequest = new RestRequest().AddJsonBody(request); + var restRequest = new RestRequest(resource).AddJsonBody(request); return client.PostAsync(restRequest, cancellationToken); } @@ -86,7 +86,7 @@ public static async Task PostJsonAsync( TRequest request, CancellationToken cancellationToken = default ) where TRequest : class { - var restRequest = new RestRequest().AddJsonBody(request); + var restRequest = new RestRequest(resource).AddJsonBody(request); var response = await client.PostAsync(restRequest, cancellationToken).ConfigureAwait(false); return response.StatusCode; } @@ -128,7 +128,7 @@ public static async Task PutJsonAsync( TRequest request, CancellationToken cancellationToken = default ) where TRequest : class { - var restRequest = new RestRequest().AddJsonBody(request); + var restRequest = new RestRequest(resource).AddJsonBody(request); var response = await client.PutAsync(restRequest, cancellationToken).ConfigureAwait(false); return response.StatusCode; }