简体   繁体   English

带授权的Vue.http.get-发出2个请求,仅在iOS上失败

[英]Vue.http.get w/ authorization - makes 2 requests and fails on iOS only

I have to make an authenticated HTTP request using a bearer token. 我必须使用承载令牌发出经过身份验证的HTTP请求。 This works flawlessly on everything I've tested...except some iOS devices. 这在我测试过的所有内容上都可以正常使用...除了某些 iOS设备。

  fetchWithToken : function( endpoint, token ){
    return Vue.http.get( urlBase + endpoint, {
      headers : {
        Authorization : 'Bearer ' + token
      }
    });
  },

From what I can tell, the request is being sent twice. 据我所知,该请求被发送了两次。 Note this function only gets called once (verified by debugging) but the server receives 2 requests. 请注意,此函数仅被调用一次(通过调试验证),但是服务器接收2个请求。 The first request contains the token and authorizes successfully. 第一个请求包含令牌并成功授权。 The second has no token and fails, returning that failure to the rest of my app. 第二个没有令牌并且失败,将失败返回给我的应用程序的其余部分。

The two HTTP requests from one call makes me think CORS preflight requests. 来自一个调用的两个HTTP请求使我认为CORS是预检请求。 However it is the same domain and the urlBase variable in that function above is a relative address ('/api/'), not a full URL. 但是,它是相同的域,上面函数中的urlBase变量是相对地址('/ api /'),而不是完整的URL。

Is iOS forcing CORS? iOS是否强迫CORS? And if so, why is the second request sent without the authorization header instead of the preflight request? 如果是这样,为什么发送的第二个请求没有授权标头,而不是预检请求?

Bad combination of events. 事件的不良组合。 The server (a symfony app) was doing a 301 redirect for endpoints that didn't end in a slash. 服务器(symfony应用程序)正在对未以斜杠结尾的端点执行301重定向。 Apparently iOS is the only user agent that does not let the authorization header carry over on a 301 redirect. 显然,iOS是唯一不让授权标头继续进行301重定向的用户代理。 So the first request had the token, it was 301'ed, and the 2nd request did not. 所以第一个请求有令牌,它是301'ed,第二个请求没有令牌。 Basically 3 hours of logging and tracing everything down to learn I need to end my endpoint calls with a /. 基本上需要3个小时的日志记录并跟踪所有内容以了解我需要使用/结束端点调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM