简体   繁体   English

Angular 9 http.获取带参数的请求

[英]Angular 9 http.Get request with paramaters

I am trying to send query parameters with a get request.我正在尝试使用获取请求发送查询参数。 This code always has an empty query {}.此代码始终有一个空查询 {}。 What am I missing?我错过了什么?

let p = new HttpParams().set('Test', "7878");
return this.http
  .get<Response>(environment.baseAPIUrl + route, 
    { 
      withCredentials: false, 
      headers: requestHeaders, 
      params: p, 
      responseType, 
      observe: observe as 'body'
    } 
  );

Basically your use of HttpParams seems okay and it's working for me.基本上你对HttpParams的使用似乎没问题,它对我有用。

Open my Stackblitz Example :打开我的Stackblitz 示例

  • open the dev-tools (F12 in Chrome)打开开发工具(Chrome 中的 F12)
  • go to the network tab go 到网络选项卡
  • now Refresh the stackblitz-browser frame: everything looks good:现在刷新 stackblitz-browser 框架:一切看起来都很好:

在此处输入图像描述

just note, that the error-message (1) will not include the url-parameters请注意,错误消息 (1) 将不包括 url 参数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM