V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
lmaritime
V2EX  ›  Android

java 发送 post 请求上传图片

  •  
  •   lmaritime · 2015-07-30 15:13:42 +08:00 · 4142 次点击
    这是一个创建于 3202 天前的主题,其中的信息可能已经有所发展或是发生改变。

    构造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));
    }

    lmaritime
        1
    lmaritime  
    OP
       2015-07-31 10:27:06 +08:00
    问题已经解决了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   759 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 20:31 · PVG 04:31 · LAX 13:31 · JFK 16:31
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.