我有一段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规范中搜索,但没有找到任何线索。我没有使用任何Transfer-Encoding或Transfer-coding。