问题:
I have been looking for a way to pass query parameters into an API call with the new HttpClientModule
's HttpClient
and have yet to find a solution.我一直在寻找一种使用新的HttpClientModule
的HttpClient
将查询参数传递到 API 调用的方法,但尚未找到解决方案。 With the old Http
module you would write something like this.使用旧的Http
模块,您将编写类似这样的内容。
getNamespaceLogs(logNamespace) {
// Setup log namespace query parameter
let params = new URLSearchParams();
params.set('logNamespace', logNamespace);
this._Http.get(`${API_URL}/api/v1/data/logs`, { search: params })
}
This would result in an API call to the following URL:这将导致对以下 URL 的 API 调用:
localhost:3001/api/v1/data/logs?logNamespace=somelogsnamespace
However, the new HttpClient
get()
method doesn't have a search
property, so I am wondering where to pass in the query parameters?但是,新的HttpClient
get()
方法没有search
属性,所以我想知道从哪里传入查询参数?
解决方案:
参考一: https://en.stackoom.com/question/34myN参考二: https://stackoom.com/question/34myN