我正在使用POST从java发送二进制数据。这是java代码:
URL url = new URL(saveURI);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("POST");
urlConnection.setDoOutput(true);
urlConnection.setDoInput(true);
urlConnection.setInstanceFollowRedirects(false);
urlConnection.setUseCaches(false);
urlConnection.setRequestProperty("Content-Type", "application/octet-stream");
urlConnection.setRequestProperty("charset", "utf-8");
urlConnection.setRequestProperty("Content-Length", Integer.toString(length));
OutputStream out = new BufferedOutputStream(urlConnection.getOutputStream());
out.write(data);
out.flush();
out.close();
大小为150216字节。 python代码:
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import sys
print "Content-Type: text/plain;charset=utf-8"
print
data = sys.stdin.read()
print len(data)
profile= profile_pb2.ProtoCharacter()
profile.ParseFromString(data)
if profile.IsInitialized():
ProfileWork.saveProfile(profile)
print profile.tag
给我22.这可能是什么问题?
编辑:添加了更多代码