通过javascript和XmlHttpRequest发送multipart / related请求

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

我正在尝试基于cpprestsdk向我自己的服务器发送multipart / related请求:

POST /test HTTP/1.1
Content-Type: multipart/related; boundary=-
---
Content-Type: application/json

{
   "testField": "testValue"
}
---
Content-Type: image/jpeg
Content-Length: 131745
Content-Transfer-Encoding: binary

[DATA (131745 bytes)]
---

请求的第二部分包含二进制格式的jpeg图像,服务器成功读取它并从该字节创建图像。但是随后在Wireshark中看到了这个请求,它显示了大约192000字节的图像数据,而不是我预期的131745。我假设所有请求数据都是通过javascript的XmlHttpRequest转换为utf-8,因为没有指定多部分/相关的字符集。有没有办法避免这种开销并只发送原始字节?

javascript xmlhttprequest multipart casablanca cpprest-sdk
1个回答
0
投票

问题是我将sendXmlHttpRequest方法的请求作为字符串值传递,而不是作为ArrayBuffer

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