Angular 8 : Headers 未在 HttpCliet.post 中正确发送
Angular 8 : Headers are not properly sent in 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.");
});
你能告诉我为什么在这段代码中 body 根本没有发送吗?
谢谢,
兹维卡
问题中的代码似乎是正确的。 Angularhttppostcan be tested here。
示例can be investigated here.
的请求
根据以上示例,API 应该存在问题,它正在处理 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.");
});
你能告诉我为什么在这段代码中 body 根本没有发送吗?
谢谢, 兹维卡
问题中的代码似乎是正确的。 Angularhttppostcan be tested here。 示例can be investigated here.
的请求根据以上示例,API 应该存在问题,它正在处理 POST 请求。