我已经创建了自定义的post方法,与原始签名几乎相同,如下所示,
postcall(url: string, body: any | null, options: {headers?: HttpHeaders | {
[header: string]: string | string[];
};
params?: HttpParams | {
[param: string]: string | string[];
};
reportProgress?: boolean;
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
withCredentials?: boolean;
} = {}): Observable<any> {
return this.http.post<any>(url,body,options.Headers?Headers:responseType);
}我无法将option作为参数传递,上面的post call.Please让我知道如何传递参数。它应该像我们在postcall()的形参中接收到的那样传递选项。
编辑-1,
我的电话是
this.http.postcall(this.resumeapiserver,body,{responseType: 'text'});或
httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json',
})
}
this.http.postcall(this.apiServer + '/applicants/', JSON.stringify(applicant), this.httpOptions)这两种方法都应该有效..



发布于 2021-08-31 18:08:35
试试这样的东西:
post(applicant: any) {
const options = {
headers: new HttpHeaders({
'Content-Type': 'application/json',
}),
};
this.http.post(this.apiServer + '/applicants/', applicant, options);
}您的postcall函数有一个错误,可能应该更改此行,如下所示:
return this.http.post<any>(url, body, options);在我看来,这个postcall函数并没有多大意义,因为它是httpClient post函数的副本。因此,也许更好的做法是直接使用post函数,就像我在第一个示例代码中展示的那样。
https://stackoverflow.com/questions/69003166
复制相似问题