Angular Set-Cookie在Safari中不起作用

时间:2018-04-10 11:44:53

标签: javascript angular typescript http-headers

在我的Angular 5应用程序中,我们使用http客户端来发布和获取请求。登录后,后端会给出一个命令来设置Cookie,该Cookie可用于在下一个请求中进行身份验证。

这看起来像:

Set-Cookie: portal_ci_session=XuATFg7Y7gwG3SKff83; path=/; secure; httponly

我创建了一个库以发布帖子请求:

const myheader = new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded')
const baseUrl = 'https://***/index.php/rest/';

@Injectable()
export class HttpprocessingService {

  constructor(private http: HttpClient,private router: Router) { }

  // do an post request 
  public doPost(url : string,postparameters : any){

    var postbody = new HttpParams();        

    for(var key in postparameters) {
      postbody = postbody.append(key,postparameters[key]);
    }

    return this.http.post(baseUrl+url,postbody,{headers:myheader,withCredentials:true});    

当我在Chrome中对登录进行发布请求时,Cookie会通过响应标头收到,并自动设置在下一个请求的请求标头中。

但是在使用Safari时,这种机制不起作用。 Set-Cookie的响应头是相同的,但在下一个请求时,请求头是空的。

我做错了什么?

我在本地主机中运行Angular:4200。

0 个答案:

没有答案