Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用angular4服务在POST请求的头上设置cookie_Angular_Http_Cookies - Fatal编程技术网

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

使用angular4服务在POST请求的头上设置cookie,angular,http,cookies,Angular,Http,Cookies,我想使用angular4通过HTTP POST请求头传递一些cookie。在这里,我调用一个外部API并尝试传递这个特定的cookie。我在谷歌上搜索过,但还没有找到正确的解决方案。请帮我做同样的事。以下是我尝试过的代码 public getTransactionStatus(transactionID: string): Promise<any> { let header = new Headers; let body = { "transactionID": "1

我想使用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 };
      });
  }
公共getTransactionStatus(transactionID:string):承诺{ 让标题=新标题; let body={“transactionID”:“123”}; append('content-type','application/json'); append('set-cookie','test=hi;FedAuth=sadsa54ea4da5'); 返回this.http.post(uri,body,{headers:header}) .toPromise() 。然后((res)=>{ 设temp=res.json(); 返回{'statusCode':200,'message':'success','result':temp,'error':{}; }) .catch((错误)=>{ 返回{'statusCode':200,'message':'failed','result':{},'error':error}; }); }
您是否使用凭据尝试了
:true
?@AnshumanJaiswal我刚才尝试了header.append('withCredentials','true')。这是正确的实现方式吗请使用httpClient(而不是旧的和不推荐使用的http)请参阅。标题必须像“显示在中”一样添加