Issue
It seems like http post doesn’t send the data to server. I think I forgot something, but can’t see what.
Here my service
passChosenSymtom(symptoms:any){
console.log(symptoms)
const lol={symptoms: symptoms}//consider lol={'x':[0,1]}
console.log(JSON.stringify(lol))
return this.http.post(this.resultatSymptoms2,JSON.stringify(lol))
}
Component
getResult(){
this.symps.passChosenSymtom(this.allDisease).subscribe({
next: (obj) => this.assignmentForResult(obj),
error: (e) => console.error(e),
complete: () => console.info('complete')
}
)
}
Server
@app.route('/zaebal',methods =['POST'])
def dont_even_work():
print(request)
print(request.form)#I recieve this dict ImmutableMultiDict([])
print(request.args)
#I have to resend response to dont get a internal error which says server didnt return anything
response =jsonify({
'predicted_disease': 'fake'
})
response.headers.add('Access-Control-Allow-Origin', '*')
return response
Solution
I found my problem.
I write my solution here,if someone get the same problem.
So ,Http request from the client (Angular) sends the Json format data.But the server (Flask) receives data with another format (specific format for Flask) ,so after receiving the request you should use request.get_json()
to get the json from request.And dont use Json.stringify in client kind useless.
Answered By – Nurbek Ss
This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0