quick-cocos2d-x下载文件
生活随笔
收集整理的這篇文章主要介紹了
quick-cocos2d-x下载文件
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
服務(wù)器端仍然是一個servlet,代碼如下:
public class DownServlet extends HttpServlet {private static final long serialVersionUID = 1L;@Overrideprotected 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.requestrequest:saveResponseData("a.zip")endlocal request1 = network.createHTTPRequest(callback1, "http://localhost:8080/download", "POST") request1:start()
說明:http://....../download是上面servlet的響應(yīng)url,當(dāng)Lua訪問此url時,服務(wù)器將文件數(shù)據(jù)發(fā)送到客戶端。
總結(jié)
以上是生活随笔為你收集整理的quick-cocos2d-x下载文件的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Win11怎么禁止软件后台运行?Win1
- 下一篇: 华为管理学案例分析_华为管理课程