有什么方法可以处理angularJS 1或JS中的HTTP请求307重定向?我们正在尝试将Nest与我们的应用程序集成在一起,为此,我们需要调用Nest API来返回307重定向URL,详细信息请参见下面的链接
https://developers.nest.com/documentation/cloud/how-to-handle-redirects
它似乎在android上运行良好,但在iOS应用上却无法按预期运行。我相信它不会转发第二个请求的授权令牌。如果我们在请求中使用重定向URL,那么它似乎可以正常工作,但问题是重定向URL不断变化。希望有人能在这里帮助我们吗?
答案 0 :(得分:0)
您始终可以创建自定义Http拦截器并根据您的意愿处理所有请求/响应。这是HttpInterceptor服务的简单实现。
(function () {
'use strict';
app.factory('HttpInterceptor', HttpInterceptor);
HttpInterceptor.$inject = [
'$q'
];
function HttpInterceptor($q) {
return {
'request': function (config) {
//do magic here
},
'requestError': function (rejection) {
if (rejection.status === 307) {
//do magic here
}
return $q.reject(rejection);
},
'response': function (response) {
//do magic here
},
'responseError': function (rejection) {
if (rejection.status === 307) {
//do magic here
}
return $q.reject(rejection);
}
};
};
})();
希望这会有所帮助。
答案 1 :(得分:0)
好吧,我使用下面的cordova插件来工作。
https://www.npmjs.com/package/cordova-plugin-advanced-http
它允许我禁用重定向。我能够掌握重定向URL并使用适当的标题进行另一个调用。它解决了我的问题,不确定是否还有其他更好的方法可以做到这一点。