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

97
Visualizações
Content of body has been changed when send a HTTP Post request from Angular front-end to server side

In server side I used FastAPI framework to create API.

In Angular , I created a service to send a HTTP Post request like the following:

 runTest(
    questionId: string,
    language_name: string,
    code: string
  ): Observable<any> {
    console.log(code)
    //use http params for query parameters
    
    let params = new HttpParams().set('language',language_name);
    
    let apiUrl = `${this.BASE_URL}/question/${questionId}/run_test` ;
    return this.http.post<any>(apiUrl,code , { params: params })
  }

I place code as body of HTTP Post request. Before I send request I console.log(code) to check content of code . The content of code is type of string and it looks like the following:

def add(a:float,b:float) -> float:
    sum = a+b
    return sum

In Server side the corresponding API that I wrote by FastAPI framework like the following:

@router.post("/{id}/run_test")
async def run_test(id:str=Path(...), language: str = Query(...), code: str = Body(...)):
    
    print(code)

But code I got when print(code) is:

def add(a:float,b:float) -> float:
    tong = a+b
        return tong

As you can see,the content of code when I sent in front-end and the content of code when I got in server side is different .

I don't know what happens during process of send HTTP Post request to server side.Please help me. And I'm sorry for my English .

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