烧瓶饼干未使用 ajax 请求设置



我正在尝试在来自反应应用程序的 ajax 请求上设置来自 Flask 服务器的 cookie。我做了一个简单的测试用例,即便如此,cookie也会在响应中发送,但没有在浏览器中设置

瓶:

@app.route('/is_alive', methods = ['POST'])
def alive():
resp = app.make_response("There should be a cookie")
resp.set_cookie("testing", 'testing')
return resp

Javascript:

static isAlivePost() {
return new Promise(resolve => {
let options = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
credentials: 'same-origin',
body: JSON.stringify({
firstParam: 'true'
})
}
fetch(endpoints.MOCK_API + 'is_alive', options)
.then(response => {
resolve(response.text());
}).then(function(data) {
resolve(data);
})
.catch(e => {
reject(e);
});
});
}

credentials: 'same-origin'需要credentials: 'include'

最新更新