Angular 8:HttpCliet.post中没有正确发送头信息。

问题描述 投票:0回答:1

下面的代码可以用。

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.");
      });

然后我又试了下面的代码

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.");
        }); 

你能告诉我为什么在这段代码中,body没有被发送?

谢谢你,Zvika

angular httpclient
1个回答
1
投票

问题中的代码似乎是正确的。Angular http post 可在此测试.示例的要求 可查.

根据上面的例子,应该是API的问题,它在处理POST请求。

© www.soinside.com 2019 - 2024. All rights reserved.