首页 > 解决方案 > Angular 8:标头未在 HttpCliet.post 中正确发送

问题描述

以下代码有效:

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

你能告诉我为什么在这个代码正文中根本没有发送吗?

谢谢你,兹维卡

标签: angularhttpclient

解决方案


问题中的代码似乎是正确的。Angular http 帖子可以在这里进行测试。示例的要求可以在这里调查

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


推荐阅读