我有一段 Java 代码将字节数组传输到 HTTP 服务器:
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);
connection.setRequestMethod("POST");
connection.setRequestProperty("Connection", "Keep-Alive");
connection.setRequestProperty("Content-Type", "multipart/form-data; boundary="
+ myBoundary);
connection.setRequestProperty("Content-Length", 1024);
我使用此代码传输大小大于 1024 的字节数组。它运行良好。但是实际的 HTTP 消息(由Wireshark捕获)显示 Content-Length 的值是实际大小而不是 1024。为什么?
我在HTTP 规范中进行了搜索,但没有找到任何提示。我没有使用任何传输编码或传输编码。