【发布时间】:2018-01-27 03:37:06
【问题描述】:
我的应用程序有一个小问题: 我必须在一个 url 的响应中得到一些 cookie,其中一个是通过向另一个 url 发出请求来获得的。请求已完成,但我无法获取 cookie,因为当我获得请求的结果时,我会被重定向到站点/站点。 所以我的问题是:有没有办法授权第一次重定向,而不是第二次?
我知道我正在使用 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> ' }
【问题讨论】:
-
您找到解决方案了吗?有一个非常相似的问题。
-
嗨,我没有找到任何解决方案,但我通过使用 Cookies 代替它。 :/希望它会有所帮助
标签: javascript react-native fetch axios