Ada*_*ski 4 http typescript angular-http angular
我想问你关于 get 方法的参数。我有这样的事情:
path = 'https://example.com/api';
const params = new HttpParams();
params.append('http', 'angular');
return this.http.get(path, {params: params});
Run Code Online (Sandbox Code Playgroud)
我以为我会有这样的网址:
www.example.com/api?http=angular
但实际上,当我在 chrome 的网络选项卡中检查时,请求 url 是
www.example.com/api
当我想要路径时应该怎么做: www.example.com/api?http=angular 是否可以在没有 chrome 的情况下检查使用方法的请求 url?我的意思是在使用该方法的服务中?
您需要在append
函数调用后重新分配。它返回一个新的HttpParams对象。
const params = new HttpParams().append('http', 'angular');
Run Code Online (Sandbox Code Playgroud)
这是append 的文档。可以看到它返回了HttpParams实例
append(param: string, value: string): HttpParams
Construct a new body with an appended value for the given parameter name.
Run Code Online (Sandbox Code Playgroud)
是否可以在没有 chrome 的情况下检查所用方法的请求 url?
您可以创建一个HttpInterceptor并查看将在intercept
函数实现中使用的整个 url 。
归档时间: |
|
查看次数: |
2983 次 |
最近记录: |