[英]pass params in angular get httpclient request
我將通過標題或參數設置數據並使用get方法。
我已經創建了我的服務。
public openFile(pathFile) {
let url='/download/';
let mockUrl;
let file= new HttpHeaders();
file=pathFile
return this.httpClient.get(url,file);
}
VS代碼中的問題我收到此錯誤:
Argument of type 'HttpHeaders' is not assignable to parameter of type '{ headers?: HttpHeaders | { [header: string]: string | string[]; }; observe?: "body"; params?: Ht...'
當我嘗試運行該服務時,服務器給我這個錯誤:
{timestamp: 1524743028303, status: 400, error: "Bad Request", exception: "org.springframework.web.bind.MissingServletRequestParameterException", message: "Required String parameter 'pathFile' is not present", …}
編輯:我錯過了另一個錯誤,因為我復制了您的示例,只更改了一行。
看一下httpClient.get行。 您不會直接傳遞標頭,而是傳遞具有標頭字段的對象。
public openFile(pathFile) {
let url='/download/';
let headers= new HttpHeaders();
headers.set('file', pathFile);
return this.httpClient.get(url, { headers: headers });
}
正如@infodev在評論中提到的那樣,您可以省去HttpHeaders類。 然后看起來像這樣:
public openFile(pathFile) {
let url='/download/';
return this.httpClient.get(url, { headers: { file: pathFile } });
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.