我正在使用服务器分发一些文件(以zip格式),但是,我希望用户输入CAPTCHA,然后才能下载文件。
这带来了一个新问题,因为代码:
private void sendFileResponse(final String filename, byte[] response, HttpExchange httpExchange) { //if (response != null && response.length > 0 && httpExchange != null) { try { httpExchange.setAttribute(HTTPExchange.HeaderFields.Content_Type.toString(), "application/zip"); OutputStream outputStream = httpExchange.getResponseBody(); httpExchange.sendResponseHeaders(200, response.length); outputStream.write(response); outputStream.flush(); outputStream.close(); httpExchange.getRequestBody().close(); } catch (Exception e) { System.out.println(Misc.getStackTrace(e)); } } // }
...将导致该文件被命名为下载请求网页的URL。例如,如果用户输入正确的验证码并从/download.html下载文件,则他们收到的文件将是download.html,而不是我的文件名。
如何使服务器将文件作为文件名发送并同时刷新网页?
谢谢。