Angular/Flask http post不起作用,数据尚未发送



http post似乎没有将数据发送到服务器。我想我忘了什么,但看不清是什么。

这是我的服务


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))
}

组件

getResult(){
this.symps.passChosenSymtom(this.allDisease).subscribe({
next: (obj) => this.assignmentForResult(obj),
error: (e) => console.error(e),
complete: () => console.info('complete')
}
)
}

服务器

@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

我发现了我的问题。如果有人遇到同样的问题,我会在这里写下我的解决方案。因此,来自客户端(Angular(的Http请求发送Json格式的数据。但是服务器(Flask(接收到另一种格式的数据(Flask的特定格式(,因此在收到请求后,您应该使用request.get_json()从请求中获取json。不要在客户端使用Json.stringify。

最新更新