我在我的应用程序中遇到了一个小问题:
我需要从一个URL的响应中获取一些cookie,这个URL是通过向另一个URL发出请求获得的。请求已经发送了,但是我无法获取到cookie,因为当我获取到请求结果时,我被重定向到了该网站。
所以我的问题是:有没有办法授权第一次重定向,但不授权第二次重定向?
我正在使用react-native,Axios解决方案中的
请求代码:
我正在使用react-native,Axios解决方案中的
maxRedirects: 1
在我的情况下不起作用。对于fetch中的redirect: 'manual'
也是一样。请求代码:
fetch(
'https://gitlab.blablabla.fr/users/auth/ldapmain/callback',
{
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'accept-charset':'utf-8',
},
body: querystring.stringify({
authenticity_token: this.state.token,
username: this.state.username,
password: this.state.password,
}),
redirect: 'manual',
credentials: 'include',
withCredentials: 'true',
}
).then( (responseData2) => {
console.log(this.state.username +"/"+ this.state.password+ "/"+this.state.token + "/"+ this.state.utf8);
console.log(responseData2);
})
并显示出的响应:
Response {
type: 'default',
status: 200,
ok: true,
statusText: undefined,
headers:
Headers {
map:
{ 'x-version-id': [Object],
server: [Object],
'cache-control': [Object],
date: [Object],
'content-type': [Object],
'content-length': [Object],
'content-security-policy': [Object],
'accept-ranges': [Object],
'x-request-id': [Object],
'last-modified': [Object],
'x-frame-options': [Object] } },
url: 'https://mattermost.blablabla.fr/',
_bodyInit: '<!DOCTYPE html> <html> the html code</html> ',
_bodyText: '<!DOCTYPE html> <html> the html code</html> ' }