2011-09-23 32 views
2

在Android手机上,我使用setEntity()将FileEntity置于POST请求。使用Python瓶服务器接收来自Android的POST请求的FileEntity

HttpPost post = new HttpPost(uri); 
FileEntity reqEntity = new FileEntity(f, "application/x-gzip"); 
reqEntity.setContentType("binary/octet-stream"); 
reqEntity.setChunked(true); 
post.addHeader("X-AethersNotebook-Custom", configuration.getCustomHeader()); 
post.setEntity(reqEntity); 

当使用瓶,试过,但它不工作

f = request.body 
gzipper = gzip.GzipFile(fileobj= f) 
content = gzipper.read() 

的内容将是一个空字符串。所以我试图看看request.forms和request.files。他们都没有关键和价值。

request.files.keys() 
request.forms.keys() 

查询时,我看了一下实体:“一个请求可以传送实体”,实体有实体头和实体值。所以它可能像file-content = e.get(entity-header)。

+0

在Bottle中,'request.body'包含原始未解析的请求主体。如果它是空的,那么没有数据被发送到服务器。我会在客户端搜索错误。 – defnull

回答

1

使用该代码,手机使用分块编码发送文件。因为py-bottle不支持chunked enconding,所以这里的解决方案是重写android发送文件作为POST请求的主体。

相关问题