我正在做POST
到restlet
並且需要返回一個zip文件。但是,雖然創建的文件是zip,但該方法返回亂碼。zip格式的Restlet POST響應
我試圖包裹FileRepresentation作爲建議here:
new org.restlet.engine.application.EncodeRepresentation(org.restlet.data.Encoding.ZIP, representation);
而且還嘗試添加A產生的註釋是這樣的:
@Produces({"application/x-zip-compressed"})
但無論是作品。該表示形式返回爲亂碼字符串,並且Content-Type
標題保持爲application/octet-stream
。我錯過了什麼?
這些是請求標頭。注意Accept-Encoding: gzip, deflate
:
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36
Origin: chrome-extension://hgmloofddffdnphfgcellkdfbfbjeloo
Content-Type: application/json
Accept: */*
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.8,he;q=0.6
的響應頭:
Vary: Accept-Encoding
Last-Modified: Wed, 06 May 2015 14:49:03 GMT
Content-Disposition: attachment; filename=_backup_20150506.zip; size=162191
Date: Wed, 06 May 2015 14:49:03 GMT
Accept-Ranges: bytes
Server: Restlet-Framework/2.2.1
Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept
Set-Cookie: JSESSIONID=5F10BBBDC58D5C3D6C0474FA12C44FB9; Path=/AppName/; Domain=localhost
Content-Encoding: gzip
Content-Type: application/octet-stream
Transfer-Encoding: chunked
編輯:
MediaType mt = MediaType.APPLICATION_ZIP;
FileRepresentation fr = new FileRepresentation(file, mt);
的響應內容類型更改爲Content-Type: application/zip
:我也嘗試過創建表示在改變媒體類型但返回的值仍然是一個亂碼字符串。
您好埃迪,你能不能準確,如果您使用的Restlet的JAX-RS擴展? –
我嘗試使用Produces註解(javax.ws.rs.Produces),但沒有解決問題。 – Eddy