I'm working on an app for a school project. I'm trying to fetch a string in react, the backend has been build with C#. In the backend i'm sending a HttpResponseMessage with StringContent to the client side. But i can't seem to read the StringContent at the client side.
The Api at server side:
[HttpGet("{id}")]
public async Task<HttpResponseMessage> downloadDocument(int id)
{
try
{
string base64String = await this.DocumentService.downloadDocument(id);
var response = new HttpResponseMessage(HttpStatusCode.OK);
response.Content = new StringContent(base64String);
return response;
}
catch (Exception ex)
{
var response = new HttpResponseMessage(HttpStatusCode.ExpectationFailed);
response.Content = new StringContent(ex.Message);
return response;
}
}
The Client side code
function downloadDocument(param: any) {
fetch(process.env.REACT_APP_API_URL + 'document/' + param.row.id, {
method: "GET",
headers: {
"Content-Type": "application/json"
}
})
.then((response) => response.json())
.then((data) => {
console.log(data);
})
}
Where i log data to the console i get the following:

I can see the content object there. but how do i get the string i've added in the HttpResponseMessage with new StringContent(base64String);