我已经在这个问题上挣扎了一段时间,我想知道这里是否有人可以帮助我。
我有一个ionic 3/angular 5应用程序,它正在访问外部API。登录时,服务器将发送一个会话id,我将使用该id对所有后续数据调用进行身份验证。Chrome和Android运行良好。Safari和iOS并非如此。
我的服务中的登录代码很简单:
public login(credentials): Observable<Object> {
let httpParams = this.httpParams;
for (let key in credentials){ httpParams = httpParams.set(key, credentials[key])};
return this.httpClient.post(this.url + this.loginEndpoint, httpParams, { withCredentials: true });
}当它被调用时:
this.authServiceProvider.login({username: this.username, password: this.password}).subscribe(data => {
<display logged in page>
});但是当我再次调用dataProvider时,Safari正在服务器上实例化一个新的会话,即。不发送来自上一个请求的会话id cookie。
CORS正常工作。这是我的服务器正在发送的头文件,包括cookie。
access-control-allow-credentials: true
access-control-allow-headers: origin, x-requested-with, content-type
access-control-allow-origin: http://localhost:8100
content-encoding: gzip
content-length: 95
content-type: text/javascript
date: Wed, 21 Mar 2018 15:55:50 GMT
server: Apache-Coyote/1.1
set-cookie: JSESSIONID=BE1997D948436D29A90DA24DC518E29F; Path=/api/; HttpOnly
status: 200
vary: Origin,Accept-Encoding以下是Chrome在以下请求中发送的标头:
:authority: api.com
:method: POST
:path: /api/login.jsp
:scheme: https
accept: application/json, text/plain, */*
accept-encoding: gzip, deflate, br
accept-language: en-US,en;q=0.9
content-length: 283
content-type: application/x-www-form-urlencoded;charset=UTF-8
cookie: JSESSIONID=BE1997D948436D29A90DA24DC518E29F; _ga=GA1.2.744976386.1521627198; _gid=GA1.2.533597894.1521627198
origin: http://localhost:8100
referer: http://localhost:8100/?ionicplatform=android&http://localhost:8100/ionic-lab
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36下面是Safari为第二个请求发送的头文件:
Referer: http://localhost:8100/?ionicplatform=android&http://localhost:8100/ionic-lab
Content-Type: application/x-www-form-urlencoded;charset=UTF-8
Origin: http://localhost:8100
Host: api.com
Accept: application/json, text/plain, */*
Connection: keep-alive
Accept-Language: en-us
Accept-Encoding: br, gzip, deflate
Content-Length: 283
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/604.4.7 (KHTML, like Gecko) Version/11.0.2 Safari/604.4.7如果我进入Safari的首选项,取消安全>网站跟踪>阻止跨站点跟踪,一切都会正常工作。Safari发送了cookie。
Referer: http://localhost:8100/?ionicplatform=android&http://localhost:8100/ionic-lab
Content-Type: application/x-www-form-urlencoded;charset=UTF-8
Origin: http://localhost:8100
Host: api.com
Accept: application/json, text/plain, */*
Connection: keep-alive
Accept-Language: en-us
Accept-Encoding: br, gzip, deflate
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/604.4.7 (KHTML, like Gecko) Version/11.0.2 Safari/604.4.7
Cookie: JSESSIONID=32D79DD5171A6B82783252CE22E55083
Content-Length: 283但显然,这不是iOS应用程序用户的解决方案。
有谁有这方面的经验吗?多年来,我发现很多人都有类似的问题,但大多数解决方案对我都不起作用
如有任何帮助,我们不胜感激!如果你需要更多信息请告诉我。
发布于 2018-03-22 20:50:42
尝试使用此CORDOVA PLUGIN
这应该可以解决这个问题
https://stackoverflow.com/questions/49426045
复制相似问题