可以在http请求中添加headers选项,将ETag头手动添加到请求头中。
示例代码:
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders, HttpResponse } from '@angular/common/http';
import { Observable } from 'rxjs';
@Injectable()
export class DataService {
private serviceUrl = 'http://example.com/api/data';
constructor(private http: HttpClient) {}
getData(id: number): Observable> {
const headers = new HttpHeaders({
'ETag': 'your ETag value'
});
return this.http.get(this.serviceUrl + '/' + id, { headers, observe: 'response' });
}
}