【发布时间】:2020-02-20 10:57:14
【问题描述】:
首先我将用户 ID 和密码从 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.route('/login', methods=['GET','POST'])中添加OPTIONS吗? -
哪个端口是角度运行,哪个是闪存运行。您是否设置了代理配置?这里有关于如何设置代理的说明:angular.io/guide/build
标签: python-3.x angular typescript flask angular-ui-router