quick-cocos2d-x下載檔案
伺服器端仍然是一個servlet,程式碼如下:
public class DownServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@Override
protected void service(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String path = "D:/Downloads/LuaXML_101012.zip";
File file = new File(path);
InputStream is = new BufferedInputStream(new FileInputStream(file));
byte[] buffer = new byte[is.available()];
is.read(buffer);
is.close();
response.reset();
response.addHeader("Content-Disposition", "attachment;filename="
+ new String(file.getName().getBytes("utf-8"), "ISO-8859-1"));
response.addHeader("Content-Length", "" + file.length());
OutputStream toClient = new BufferedOutputStream(response.getOutputStream());
response.setContentType("application/octet-stream");
toClient.write(buffer);
toClient.flush();
toClient.close();
}
}
下面是客戶端lua指令碼:
local function callback1(event)
local ok = (event.name == "completed")
local request = event.request
request:saveResponseData("a.zip")
end
local request1 = network.createHTTPRequest(callback1, "http://localhost:8080/download", "POST")
request1:start()
說明:http://....../download是上面servlet的響應url,當Lua訪問此url時,伺服器將檔案資料傳送到客戶端。
相關文章
- 檔案下載
- 00、下載檔案
- Ajax 下載檔案
- FastApi下載檔案ASTAPI
- MVC 下載檔案MVC
- js 檔案下載JS
- Servlet下載檔案Servlet
- httpWebRequest 檔案下載HTTPWeb
- php檔案下載PHP
- .net 檔案下載
- php 檔案下載PHP
- HttpClient 下載檔案HTTPclient
- Response下載檔案
- 檔案程式設計、檔案下載程式設計
- iOS開發網路篇之檔案下載、大檔案下載、斷點下載iOS斷點
- Flutter 下載檔案操作Flutter
- SpringMVC檔案下載SpringMVC
- 【springmvc】下載檔案SpringMVC
- 使用PHP下載檔案PHP
- 檔案下載相關
- ftp下載指定檔案FTP
- C#檔案下載C#
- PHP檔案下載原理PHP
- 檔案上傳下載
- SpringMVC檔案上傳下載(單檔案、多檔案)SpringMVC
- java上傳檔案跟批量下載檔案Java
- 利用secure crt下傳下載檔案
- 如何下載 Ubuntu 映象檔案?Ubuntu
- 檔案下載(URL,文件流)
- Flutter實現檔案下載Flutter
- 檔案下載那點事
- AJAX實現檔案下載----
- CentOS 7映象檔案下載CentOS
- 檔案上傳與下載
- python 下載檔案demoPython
- JAVA檔案上傳下載Java
- 前端如何下載檔案流前端
- python之檔案下載Python