/// <summary> /// Returns true if the response content uses the JSON content type. /// </summary> /// <param name="response">The response.</param> /// <returns>True if the response content uses the JSON content type ("application/json" or "application/schema+json") and the content is not empty.</returns> public static bool HasJson(this WebServiceResponse response) { bool hasJson = response.Content?.Headers.ContentLength > 0; var contentType = response.Content?.Headers.ContentType?.ToString(); hasJson &= contentType is object && JsonResponseUtility.IsJsonContentType(contentType); return(hasJson); }
/// <summary> /// Returns true if the response content uses the JSON content type. /// </summary> /// <param name="response">The response.</param> /// <returns>True if the response content uses the JSON content type ("application/json" or "application/schema+json") and the content is not empty.</returns> public static bool HasJson(this HttpResponseMessage response) { // Allow null ContentLength var hasJson = response.Content?.Headers.ContentLength != 0; var contentType = response.Content?.Headers.ContentType?.ToString(); hasJson &= contentType is object && JsonResponseUtility.IsJsonContentType(contentType); return(hasJson); }