2011-09-23 88 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請求的主體。

相關問題