Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

355
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda