Search code examples
angularhttpclient

Angular 8 : Headers are not properly sent in HttpCliet.post


The following code works:

this.http.post (TGT_IP,body, {responseType: 'arraybuffer'}).subscribe(
      (val) => {
          console.log("POST call successful value returned in body", 
                      val);

      },
      response => {
          console.log("POST call in error", response);
      },
      () => {
          console.log("The POST observable is now completed.");
      });

Then I tried the following code:

var body = [0x11,0x22,0x33,0x44];
this.http.post (TGT_IP,
                  body, 
                  { headers: new HttpHeaders({'Content-Type': 'octet/stream',
                                              'Accept': 'octet/stream'}),
                    responseType: 'arraybuffer'
                    }).subscribe(
        (val) => {
            console.log("POST call successful value returned in body", 
                        val);

        },
        response => {
            console.log("POST call in error", response);
        },
        () => {
            console.log("The POST observable is now completed.");
        }); 

Can you please tell why in this code body is not sent at all ?

Thank you, Zvika


Solution

  • The code in the question seems to be correct. The Angular http post can be tested here. The request of the example can be investigated here.

    Based on the above example there should be an issue with the API, which is handeling the POST request.