R
R
Roman Rakzin2020-05-04 22:06:08
JavaScript
Roman Rakzin, 2020-05-04 22:06:08

How to pass post parameters to http.client Angular?

What could be the reason why angular httpClient doesn't send post parameters?
At once I will tell - I read the documentation.
The server in php and when tested via Postman and debugging tools accepts post parameters.
I even made the output of all post parameters, but for some reason, Angular does not send them.


public urlapi = 'http://localhost:81/';
      private httpOptions = {
        headers: new HttpHeaders({
          'Content-Type':  'application/json'
        })
      };

    public GetOrders(): Observable<[]>{
            const postBody = {'param': 'value'};
            return this.http.post(this.urlapi, postBody , this.httpOptions)
            .pipe(map(data => {
              return data.map((element: any) => {
                  return {id: element.Id};
              });
    }));

I want to count these parameters on the server, but I see an empty list of parameters, which I output `var_dump($_REQUEST);`

What could be the matter if the backend is working and outputting data? I rummaged through a bunch of documentation for half a day and I can’t figure it out. Could this be related to headers?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Rakzin, 2020-05-05
@TwoRS

It's weird, but it worked

const formData = new FormData();
    formData.append('picture', file);
    formData.append('OrderId', this.ordersService.SelectedOrder['Id']);

and I substitute formData
return this.http.post(this.urlapi, formData , this.httpOptions)

But it didn’t work like this, although everywhere on the Internet it is written like this `const formData = {'param': 'value'};`

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question