我正在使用Android应用程序向CherryPy服务器发送base64编码的字符串。Android代码的工作原理如下:
URL url = new URL("http://foo.bar/blabla");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("Content-Type", "application/octet-stream");
conn.setDoOutput(true);
conn.setFixedLengthStreamingMode(base64s.length());
OutputStream out = new BufferedOutputStream(conn.getOutputStream());
out.write(base64s.getBytes());
因此,您可以说发送的字节数等于Content-Length
头中的字节数。但是,在Python中,当我运行以下命令时:
cl = cherrypy.request.headers['Content-Length']
rawbody = cherrypy.request.body.read()
print "{} bytes, {}".format(len(rawbody), cl)
数字cl
和len(rawbody)
是不同的。你知道吗
怎么会这样?你知道吗
你的服务器应该发送一个“closeheader”,这样客户端就不会为他发送结束流了。你知道吗
也许你忘了用
out.close();
关闭流?你知道吗相关问题 更多 >
编程相关推荐