Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

671
Vistas
Not able to pass parameter in POST url angular

Hi I am trying to pass parameter in POST method url in angular service to construct a URL to fetch some data from an API but when I am calling it on component file I am getting error response.

Where am I doing wrong ?

Example I need this type of url to pass:- https://something/api/v1/map/GetdetailsById?ID=EF-345-RHDJI34-EHI3

In service I am doing :-

// Http Options
  httpOptions = {
    headers: new HttpHeaders({
      'Content-Type': 'application/json'
    })
  };

//POST API to show lists
  getOTList(): Observable<any> {
    const params = new HttpParams()
    .set('ID', 'EF-345-RHDJI34-EHI3');
    return this.http
      .post<any>(`${environment.Url}` + `${APIs.getList}`,{params}, this.httpOptions)
      .pipe(
        retry(1),
        catchError(this.handleError)
      )
  }

Ang in component I am doing :

ngOnInit(){
    this.getLists();
  }

getLists(){
    this.addService.getOTList().subscribe((response:any) => {
      if (response.IsSuccess == true) {
        console.log(response);
      }
      else {
        console.log("something is wrong.") //<========== getting this message in console
      }
    });
  }
over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

We are doing a POST request, therefore we need to add a body. Your params should also be set into the same object as your httpOptions, setting the content type to json is really not needed with the HttpClient, it happens automagically, so I would just do:

return this.http.post<any>(`${environment.Url}` + `${APIs.getList}`, {}, { params })

Notice the empty body {}. As you are not even passing a body, this wouldn't need to be a POST request, just thought I'd mention. Also, please don't use any. Typing your data will help you in the future! :)

over 4 years ago · Santiago Trujillo Denunciar

0

You need to set your params const to the params object in the your http.post call, like this: {params: params}.

So your updated service function should look like this:

getOTList(): Observable<any> {
   const params = new HttpParams()
   .set('ID', 'EF-345-RHDJI34-EHI3');
   return this.http.post<any>(`${environment.Url}` + `${APIs.getList}`, {params:params}, this.httpOptions)
      .pipe(
         retry(1),
         catchError(this.handleError)
      )
}
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda