小编Ale*_*aud的帖子

防止axios /提取重定向

我的应用程序中有一个小问题:我必须在一个URL的响应中获得一些cookie,其中一个是通过对另一个URL的请求获得的。请求已完成,但是我无法获取cookie,因为当我获得请求的结果时,我将被重定向到该站点。 所以我的问题是:是否有一种方法可以授权第一个重定向,但不能授权第二个重定向?

我以为我使用的是react-native,而axios解决方案maxRedirects: 1在我的情况下不起作用。同为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);


                    })
Run Code Online (Sandbox Code Playgroud)

并显示响应:

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], …
Run Code Online (Sandbox Code Playgroud)

javascript fetch react-native axios

5
推荐指数
1
解决办法
3073
查看次数

标签 统计

axios ×1

fetch ×1

javascript ×1

react-native ×1