Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

353
Views
How to read HttpResponseMessege StringContent in react

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: enter image description here

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

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!