构造http header时,设置content-length为内容部分字节数,但是总是无效。
通过wireshark抓到的包和设置的content-length不符合。
private void initConnection() throws Exception {
conn = (HttpURLConnection) this.url.openConnection();
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setUseCaches(false);
conn.setConnectTimeout(1000); //连接超时为10秒
conn.setRequestMethod("POST");
conn.setRequestProperty("connection", "keep-alive");
conn.setRequestProperty("Content-Type","multipart/form-data; boundary=" + boundary);
conn.setRequestProperty("Content-Length",String.valueOf(5889));
}