【发布时间】:2018-10-15 08:28:59
【问题描述】:
我正在尝试使用以下代码发布二进制数据:
let headers = new Headers()
headers.append('Content-Type', 'application/json')
this.http.post("http://localhost:8080/api/load",
requestBytes,
{
headers: headers
}).subscribe((data) => {
console.log("success!!!")
})
requestBytes 的类型为 Uint8Array
请求负载如下所示
{
"0": 10,
"1": 1,
"2": 49
}
正如您所看到的,这似乎是一个 dict,而我预计它是一个字节数组。这会导致服务器混乱。
我尝试将 Content-Type 更改为 application/octet-stream 并传入 buffer 而不是数组,但这也没有帮助。在这种情况下,有效载荷是空的。
【问题讨论】:
-
使用
application/octet-stream并发送requestBytes.buffer而不是requestBytes。 -
@AnshumanJaiswal 尝试过,正如我的问题的最后一个块中提到的那样
标签: javascript angular