gpt4 book ai didi

angular - 在可观察的 Angular http 中传递 header

转载 作者:可可西里 更新时间:2023-11-01 16:59:08 25 4
gpt4 key购买 nike

如何在 http post 请求中传递 header 。

import { Http, Response } from '@angular/http';

import { HttpHeaders } from '@angular/common/http';

import { Observable } from 'rxjs';
import { map, catchError } from 'rxjs/operators';

getStreamingURL(): Observable<any> {
const headers: HttpHeaders = new HttpHeaders({
'deviceType': 'pc',
'os': 'web'
});

const options = {
'headers': headers
};
return this.http.post(
environment.apiUrl + '/livetv/apis/v1.0/stream',
{
'channelId': 142
}, options
).pipe(map((res) => {
return res.json();
}));
}

最佳答案

简化版:

import { Http, Headers, RequestOptions, Response } from '@angular/http';

const headers: HttpHeaders = new HttpHeaders({
'deviceType': 'pc',
'os': 'web'
});

const options = new RequestOptions({ headers: headers });

return this.http.post(urlToPass, options);

关于angular - 在可观察的 Angular http 中传递 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53593198/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com