java post 图片上传_java 发送 post 请求上传图片
生活随笔
收集整理的這篇文章主要介紹了
java post 图片上传_java 发送 post 请求上传图片
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
構造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));
}
總結
以上是生活随笔為你收集整理的java post 图片上传_java 发送 post 请求上传图片的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: apt ubuntu 指定ipv4_ma
- 下一篇: html 网页主题设置吗,如何使用css