ASP调用WINRAR压缩文件, ERR_CONTENT_LENGTH_MISMATCH

slysmart 2019-01-14 10:52:29
压缩3M以下时正常,超过了CHROME就显示 "该网页无法正常运作 ,ERR_CONTENT_LENGTH_MISMATCH"信息
哪位知道如何解决这个问题,TKS
...全文
314 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
slysmart 2019-01-22
  • 打赏
  • 举报
回复
下面是下载函数,压缩大文件完成了,下载一直无法完成,页面假死

Function  downloadFile(strFile)    
'  make  sure  you  are  on  the  latest  MDAC  version  for  this  to  work    
'  -------------------------------------------------------------     
'  get  full  path  of  specified  file    
strFilename  =  server.MapPath(strFile)   
'  clear  the  buffer    
Response.Buffer  =  True    
Response.Clear    
'  create  stream    
Set  s  =  Server.CreateObject("ADODB.Stream")    
s.Open    
'  Set  as  binary    
s.Type  =  1    
'  load  in  the  file    
on  error  resume  next    
'  check  the  file  exists    
Set  fso  =  Server.CreateObject("Scripting.FileSystemObject")    
if  not  fso.FileExists(strFilename)  then    
    Response.Write("<h1>Error:</h1>"  &  strFilename  &  "  文件不存在<p>")    
    Response.End 
end  if    
'  get  length  of  file    
Set  f  =  fso.GetFile(strFilename)    
intFilelength  =  f.size   

s.LoadFromFile(strFilename)    
if  err  then    
   Response.Write("<h1>Error:文件下载错误  </h1>""<p>")    
   Response.End    
end  if    
'  send  the  headers  to  the  users  browser    
Response.AddHeader  "Content-Disposition",  "attachment;  filename="  &  f.name    
Response.AddHeader  "Content-Length",  intFilelength    
Response.CharSet  =  "UTF-8"    
Response.ContentType  =  "application/octet-stream"    
 
'  output  the  file  to  the  browser  
Response.BinaryWrite  s.Read    
Response.Flush    
'  tidy  up    
s.Close    
Set  s  =  Nothing    
End  Function  
slysmart 2019-01-21
  • 打赏
  • 举报
回复
引用 1 楼 hookee 的回复:
如果是和content length相关,应该是输出的问题吧,计算下压缩后的文件大小,输出正确的content-length http头试试看
感觉和这个有关,但是没找到相关设置方法,都是C#的
csdn_aspnet 2019-01-18
  • 打赏
  • 举报
回复
服务器用WScript.Shell组件调用winrar中的rar.exe,在代码的同目录要上传cmd.exe和rar.exe 

用法:rar.asp?path=要压缩的文件夹&rarname=压缩后的文件名&includefolder=包括子文件夹就不会空 
<%
'用法http://xx/rar.asp?path=要压缩的文件夹&rarname=压缩后的文件名&includefolder=包插子文件夹就不会空,
on error resume next
AppPath=server.mappath(".")&"/" '存放RAR.EXE和CMD.EXE的路径
zipfolder=server.mappath(request("path"))&"/" '要压缩的文件或文件夹
rarfile = request("rarname")
thispath = server.mappath(".")&"/"
if zipfolder<>"" and rarfile<>"" then
Set Shell = Server.CreateObject("WScript.Shell")
if err.number<>0 then
response.write "服务器不支持"
response.end
end if
if request("includefolder")<>"" then
cmd= thispath&"cmd.exe /c "&thispath&"rar.exe a -ep1 -r -t -o+  "&thispath&rarfile&"  "& zipfolder &""
else
cmd= thispath&"cmd.exe /c "&thispath&"rar.exe a -ep1 -t -o+  "&thispath&rarfile&"  "& zipfolder &""
end if
'response.write cmd
RetCode = Shell.Run(cmd,1, True)
response.write "<a href='"&rarfile&"'>"&rarfile&"</a>"
if err.number<>0 then
response.write "<a href='"&rarfile&"'>"&rarfile&"</a>"
else
response.write err.description
end if
else
response.write "没有参数"
end if
%>
hookee 2019-01-14
  • 打赏
  • 举报
回复
如果是和content length相关,应该是输出的问题吧,计算下压缩后的文件大小,输出正确的content-length http头试试看

28,409

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧