better support of raw data transfer
This commit is contained in:
@@ -55,7 +55,16 @@ public class ApiClient(string apiUrl) : IApiClient
|
||||
TResponse? result = null;
|
||||
|
||||
if (res.IsSuccessStatusCode)
|
||||
result = serializer.Deserialize(await res.Content.ReadAsStringAsync(), typeof(TResponse)) as TResponse;
|
||||
{
|
||||
var mediaType = res.Content.Headers.ContentType?.MediaType;
|
||||
if (!string.IsNullOrWhiteSpace(mediaType))
|
||||
{
|
||||
if (mediaType == "application/json")
|
||||
result = serializer.Deserialize(await res.Content.ReadAsStringAsync(), typeof(TResponse)) as TResponse;
|
||||
else if (typeof(TResponse).IsAssignableTo(typeof(ApiRawMessage)) && mediaType == "application/octet-stream")
|
||||
result = (TResponse)(object)new ApiRawMessage(await res.Content.ReadAsByteArrayAsync());
|
||||
}
|
||||
}
|
||||
|
||||
return new(res, result);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user