我正在网络中获取cookie,如以下屏幕所示
但是在浏览器中却显示为空白
前端代码REACT
if ($_FILES['video_file']['error'] != UPLOAD_ERR_OK) {
// handle the error instead of uploading e.g. give a message to user
}
后端代码
signIn: (username, password) =>
axios
.post('http://127.0.0.1:5000/login', {
data: {
Username: username,
Password: password,
},
})
.then(response => {
if (response.status === 200) {
console.log('sign in response', response);
return response;
}
})
.catch(error => {
if (error.response && error.response.status === 400) {
return error;
}
throw error;
}),
};
axios.defaults.withCredentials = true;
username = request.json['data']['Username']
password = request.json['data']['Password']
try:
u = Cognito(COGNITO_USER_POOL_ID, COGNITO_CLIENT_ID, username=username)
u.authenticate(password=password)
resp = make_success_resp({'username': u.username})
# 31557600 sec in 1 year
resp.set_cookie('ATOK',str(u.access_token),max_age=60*60*24*365*2, domain= 'app.localhost')
resp.set_cookie('IDTOK', u.id_token)
resp.set_cookie('RTOK', u.refresh_token)
resp.headers["Access-Control-Allow-Credentials"]=True
resp.headers["Access-Control-Allow-Origin"]="*"
return resp
except ClientError as e:
print(username + ": ", e.response['Error']['Message'])
return make_err_resp(e.response['Error']['Message'], 400)
答案 0 :(得分:0)
假设您的代码没有任何问题,我认为这可能是由于使用了本地主机。尝试将主机名映射到您的主机文件中的本地主机,并使用该主机名:127.0.0.1 testsite.dev
并为http://testsite.dev:port
设置cookie