我用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分。有什么问题吗?你知道吗
编辑:添加了更多代码
目前没有回答
相关问题 更多 >
编程相关推荐