使用Android HttpService创建简单http服务,如果是提供在线音乐和视频播放,需要设置head属性
public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException { String target = URLDecoder.decode(request.getRequestLine().getUri(), "UTF-8"); response.setStatusCode(HttpStatus.SC_OK); response.setHeader("Content-Type", "application/octet-stream"); response.addHeader("Content-Disposition", "attachment;filename=aaa.3gp"); InputStream is = null ; // 获取文件流; long length = 0;// 流的大小 try { response.setEntity(new InputStreamEntity(is, length); } catch (Exception e) { e.printStackTrace(); } }