我想发送一个多部分请求。不幸的是,请求失败了,因为 HttpURLConnection
库在标题和内容之间插入一个数字,如下所示:
POST / HTTP/1.1
Connection: Keep-Alive
Content-Type: multipart/form-data;boundary=*****
Transfer-Encoding: chunked
User-Agent: Dalvik/2.1.0 (Linux; U; Android 9; SM-G970F Build/PPR1.180610.011)
Host: localhost:7777
Accept-Encoding: gzip
115
test
为什么那个号码是115?怎么可能避免呢?这是我的简化代码:
FileInputStream fileInputStream = new FileInputStream(file);
URL url = new URL("http://localhost:7777");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setChunkedStreamingMode(1024);
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setRequestMethod("POST");
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(conn.getOutputStream()));
dos.writeBytes("test");
fileInputStream.close();
dos.flush();
dos.close();
暂无答案!
目前还没有任何答案,快来回答吧!