android HTTP post时Content-Length不对的问题!

pen2g pen2g 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我是想将二进制的信息传给服务器,我用的是ANDROID2.1SDK,我一打开这个语句,就抛出长度异常错误,不设置的时候能发送成功,网络抓包时发现,总会在我的二进制前面加入固定的6个长度的BYTE(ac ed 00 05 77 18,后面几位数可能变化,不知道干嘛用的,HTTP协议里面没说有这个东东啊,哪位知道吗?
conn.setRequestProperty("Content-Length",String.valueOf(tempbytes.length));

reguserpackage regpack=new reguserpackage();
regpack.setStrusername(strusername);
regpack.setStrpassword(strpassword);
byte[] tempbytes=regpack.getpackage();
//URL url = new URL("http://www.51anygo.cn:9080/q.do");
URL url = new URL("http://192.168.0.109:8080/findme/q.do");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setUseCaches(false);
conn.setConnectTimeout(10000);
conn.setRequestMethod("POST");
//Integer contentlength=tempbytes.length;
//conn.setRequestProperty("Content-type", "application/octest-stream");
//conn.setRequestProperty("Content-Length",String.valueOf(tempbytes.length));
//String location = conn.getRequestProperty("location");
//conn.connect();
OutputStream outStrm = conn.getOutputStream();
ObjectOutputStream objOutput = new ObjectOutputStream(outStrm);
//objOutput.writeObject(new String("this is a string..."));
objOutput.write(tempbytes);
objOutput.flush();
objOutput.close();
/* 取得Response内容 */
InputStream is = conn.getInputStream();
int ch;
StringBuffer b = new StringBuffer();
while ((ch = is.read()) != -1) {
b.append((char) ch);
}
//conn.connect();
int resCode = conn.getResponseCode();

网络抓包图片
...全文

相关推荐

评论 5
收藏 已收藏
分享
返回顶部
pen2g
Android 80,490 成员 91,375 内容