简体   繁体   中英

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.

Open my Stackblitz Example :

  • open the dev-tools (F12 in Chrome)
  • go to the network tab
  • now Refresh the stackblitz-browser frame: everything looks good:

在此处输入图像描述

just note, that the error-message (1) will not include the url-parameters

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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