【发布时间】:2011-08-28 16:57:25
【问题描述】:
我有一段 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 spec,但没有找到任何提示。我没有使用任何传输编码或传输编码。
【问题讨论】:
标签: java http http-headers http-content-length