【发布时间】:2017-12-04 21:36:09
【问题描述】:
我正在使用 Android 应用程序将 base64 编码的字符串发送到 CherryPy 服务器。 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) 的数字不同。
怎么可能?
【问题讨论】:
-
值是什么???发送了多少字节?
-
忘记了.close();?
-
@greenapps 确实如此。如果你把它作为一个答案,我会接受它。
标签: android python httpurlconnection cherrypy content-length