Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

356
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda