您的位置:首页 > 理论基础 > 计算机网络

Android httpUrlConnection POST 文件上传

2017-11-03 19:00 429 查看
conn.setRequestProperty("Content-Length", String.valueOf(info.getBytes().length));
出现错误的代码为:conn.setRequestProperty("Content-Length", String.valueOf(info.length()));

这个应该先将内容转换成bytes再计算它的长度length。改成下面的即可:

conn.setRequestProperty("Content-Length", String.valueOf(info.getBytes().length));
conn.setRequestProperty("Content-Length", String.valueOf(info.getBytes().length));
http://chunpeng.iteye.com/blog/631972 https://www.2cto.com/kf/201408/329538.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: