首页 > 解决方案 > Nativescript 不使用角度服务正确发送标头

问题描述

当我向我部署的 nodejs 网络服务器发送一个正常的 get 请求时,它告诉我没有在标头中发送 cookie,而我已经将它写在我的 api 服务的标头中

我的服务

  constructor(private http: HttpClient, private global: Global) { }
  verifAuth() {
    return new Promise((resolve, reject) => {
      this.http.get(`${this.global.url}verif`, this.global.header)
        .toPromise()
        .then(res => { resolve(res); })
        .catch(err => { reject(err); console.log('err', err) });
    });

我声明的默认标题

@Injectable({
    providedIn: 'root'
})
export class Global {
    url: String; header;
    constructor() {
        this.url = "https://fmm.etudiant.xyz/";
        this.header = {
            headers: new HttpHeaders({
                'Content-Type': 'application/json',
                'cookies': `xt=${appSetting.getString('xt')}`,
            }),
            withCredentials: true
        };
    }
}

当我调试请求时,我发现了这个

请求头

我希望必须解析令牌并获得用户的结果,但后端服务器告诉它没有 cookie,而它与其他网站一起工作正常

标签: androidangularapihttprequestnativescript

解决方案


尚不支持在 Http 请求中发送 Cookie,Github 上有一个开放的功能请求


推荐阅读