角度cli和烧瓶之间的原点误差

问题描述 投票:0回答:1

首先,我将用户名和密码从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))
     } 

接下来我从后端收到它

backend error

所有操作均正常运行,但在控制台上出现了跨原点错误

Error at UI console

下面提到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')

我无法找到问题出在哪里

注意:在其他连续步骤中,在登录过程中会产生交叉原点

python-3.x angular typescript flask angular-ui-router
1个回答
0
投票

在您的app.py中添加以下代码

CORS(app, supports_credentials=True)

以及从前端使用

{with-credentials :true}

它将启用前端和后端之间的通信

© www.soinside.com 2019 - 2024. All rights reserved.