I'm creating an WebAPI with C# .netcore. I have a method which gets file stream (different types) from a URL based on file id
function async Task<T> GetFile(string id) {
HttpRequestMessage request = new HttpRequestMessage();
request.RequestUri = new Uri("serverURL" + id);
request.Method = HttpMethod.Get;
HttpResponseMessage response = await httpClient.SendAsync(request,
HttpCompletionOption.ResponseContentRead, cancelToken);
var result = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<T>(result);
}
I want to return the result into a model like this
public class FileModel
{
public HttpResponseMessage File { get; set; }
}
I convert the result after that to base64 to get the file.
I get this error Unexpected character encountered while parsing value: B. Path '', line 0, position 0 because JsonConvert cannot convert the result into my FileModel class. I cannot use HttpResponseMessage instead of in the method, the method should be generic.
Thanks