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 .