lmaritime
V2EX  ›  Android

java 发送 post 请求上传图片

  •  
  •   lmaritime · Jul 30, 2015 · 12072 views
    This topic created in 4016 days ago, the information mentioned may be changed or developed.

    构造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
       Jul 31, 2015
    问题已经解决了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1179 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 17:53 · PVG 01:53 · LAX 10:53 · JFK 13:53
    ♥ Do have faith in what you're doing.