首先,我将用户名和密码从UI(角度)发布到烧瓶中
public send_login(user){
console.log(user)
return
this.http.post(this.apiURL+'/login',JSON.stringify(user),this.httpOptions)
.pipe(retry(1),catchError(this.
handleError))
}
接下来我从后端收到它
所有操作均正常运行,但在控制台上出现了跨原点错误
下面提到UI的http选项
constructor(private http: HttpClient) { }
// Http Options
httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': 'http://localhost:9000',
'Access-Control-Allow-Methods': "GET,POST,OPTIONS,DELETE,PUT",
'X-Requested-With': 'XMLHttpRequest',
'MyClientCert': '', // This is empty
'MyToken': ''
})
}
在后端声明的cors如下所示
cors = CORS(app, resources={r"/login": {"origins": "*"}})
@app.route('/login', methods=['GET','POST'])
def loginForm():
json_data = ast.literal_eval(request.data.decode('utf-8'))
print('\n\n\n',json_data,'\n\n\n')
我无法找到问题出在哪里
注意:在其他连续步骤中,在登录过程中会产生交叉原点
在您的app.py中添加以下代码
CORS(app, supports_credentials=True)
以及从前端使用
{with-credentials :true}
它将启用前端和后端之间的通信