首页 > 解决方案 > NativeScript 没有得到 Set-Cookie

问题描述

我正在用 Nativescript 构建一个应用程序,但是在执行登录功能时我有一些奇怪的行为,就像在我所做的第一次登录调用中,我得到了“Set-Cookie”标头,但随后我注销,然后当我这样做时再次登录我不再得到那个标题了。

下面你有登录服务:

_loginPost(url: string, params: any): Promise<any> {
    return new Promise<Response>((resolve, reject) => {
      const res = new Response();
      if (this.checkConnection()) {
        this.http.post(this.endpoint + url, params, {
    observe: "response",
    "Content-Type":  "application/json"
  }).toPromise().then((response: any) => {
            try {
                const cookie = response.headers.get("Set-Cookie");
                res.wasSuccess(cookie.slice(0, cookie.indexOf(";")).toString());
            } catch (error) {
              res.failed("ERROR");
            }
            resolve(res);
        }, (e) => {
          if (e && e.error) {
            if (e.status === 403) {
              res.failed("MUST_LOGOUT");
            } else {
              res.failed(e.error.cause);
            }
          } else {
            res.failed("ERROR");
          }
          resolve(res);
        });
      } else {
        res.failed("No Internet Conection");
        resolve(res);
      }
  });
  }

下面你有两个请求的图像

第一个请求: 在此处输入图像描述

第二个请求: 在此处输入图像描述

标签: angularhttpnativescriptangular-httpangular-httpclient

解决方案


推荐阅读