使用angular4服务在POST请求的标头上设置cookie

时间:2018-07-27 04:51:34

标签: angular http cookies

我想使用angular4通过HTTP POST请求标头传递一些cookie。在这里,我正在调用一个外部API,并尝试传递此特定的cookie。我已经用谷歌搜索,但是还没有找到正确的解决方案。请同样帮我。以下是我尝试过的代码。

public getTransactionStatus(transactionID: string): Promise<any> {
    let header = new Headers;
    let body = { "transactionID": "123" };
    header.append('content-type', 'application/json');
    header.append('set-cookie', 'test=hi; FedAuth=sadsa54ea4da5');
    return this.http.post(uri, body, { headers: header })
      .toPromise()
      .then((res) => {
        let temp = res.json();
        return { 'statusCode': 200, 'message': 'success', 'result': temp, 'error': {} };
      })
      .catch((error) => {
        return { 'statusCode': 200, 'message': 'failed', 'result': {}, 'error': error };
      });
  }

0 个答案:

没有答案