gpt4 book ai didi

asp读取远程文件并保存到本地代码

转载 作者:qq735679552 更新时间:2022-09-29 22:32:09 24 4
gpt4 key购买 nike

CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.

这篇CFSDN的博客文章asp读取远程文件并保存到本地代码由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.

  1. <%  
  2. dim act,ifLogin,loginUrl,loginActUrl,loginData,fileUrl,fileName  
  3. act=request.QueryString("act")  
  4. if(act="do") then   
  5.  ifLogin=Cint(request.QueryString("ifLogin"))  
  6.  loginActUrl=request.Form("loginActUrl")  
  7.  loginData=request.Form("loginData")  
  8.  fileUrl=request.Form("fileUrl")  
  9.  fileName=mid(fileUrl,instrrev(fileUrl,"/")+1)  
  10.  extPos=instrrev(fileName,"?")  
  11.  if(extPos>0) then  
  12.   fileName=left(fileName,extPos-1)  
  13.  end if  
  14.  if(ifLogin=1) then  
  15.   call PostHttpPage(loginActUrl,loginData)  
  16.  end if  
  17.  call DownloadFile(fileUrl,fileName)  
  18. else  
  19. %>  
  20. <form name="form1" method="post" action="?act=do">  
  21.   <p>是否登录:  
  22.     <input name="ifLogin" type="radio" value="1">  
  23.     是  
  24.     <input name="ifLogin" type="radio" value="0" checked>  
  25.     否  </p>  
  26.   <p>登录提交地址:  
  27.     <input name="loginActUrl" type="text" size="50">  
  28.   </p>  
  29.   <p>  
  30.     登录数据:<input name="loginData" type="text" size="50">  
  31.   </p>  
  32.   <p>  
  33.     要保存的远程文件URL:  
  34.     <input name="fileUrl" type="text" size="50">  
  35.   </p>  
  36.   <p>  
  37.     <input type="submit" name="Submit" value="提交">  
  38.     <input type="reset" name="Submit2" value="重写">  
  39.   </p>  
  40. </form>  
  41. <%  
  42. end if  
  43. Function BytesToBstr(body,code)   
  44.         dim objstream   
  45.         set objstream = Server.CreateObject("adodb.stream")   
  46.         objstream.Type = 1   
  47.         objstream.Mode =3   
  48.         objstream.Open   
  49.         objstream.Write body   
  50.         objstream.Position = 0   
  51.         objstream.Type = 2   
  52.         objstream.Charset =code  
  53.         BytesToBstr = objstream.ReadText    
  54.         objstream.Close   
  55.         set objstream = nothing   
  56. End Function   
  57. Function PostHttpPage(loginActUrl,PostData)   
  58.     Dim xmlHttp   
  59.     Dim RetStr        
  60.     Set xmlHttp = CreateObject("Microsoft.XMLHTTP")    
  61.     xmlHttp.Open "POST", loginActUrl, False  
  62.     XmlHTTP.setRequestHeader "Content-Length",Len(PostData)   
  63.     xmlHttp.setRequestHeader "Content-Type""application/x-www-form-urlencoded"     
  64.     xmlHttp.Send PostData   
  65.     If Err.Number <> 0 Then   
  66.         Set xmlHttp=Nothing  
  67.   response.Write("提交登录时出错!提交数据:"&PostData)  
  68.         Exit Function  
  69.     End If  
  70.     PostHttpPage=BytesToBstr(xmlHttp.responseBody,"GB2312")  
  71.     Set xmlHttp = nothing  
  72. End Function  
  73. '''''''''''''''''''''''''''''''''''''''''''  
  74. function DownloadFile(url,filename)  
  75.  Set xml = Server.CreateObject("Msxml2.XMLHTTP") '创建对象  
  76.  
  77.    xml.Open "GET",url,False  
  78.    xml.Send '发送请求      
  79.  
  80.    if Err.Number>0 then   
  81.   Response.Status="404"  
  82.   else  
  83.   Response.ContentType="application/octet-stream"  
  84.   Response.AddHeader "Content-Disposition:","attachment; filename=" & filename  
  85.   Range=Mid(Request.ServerVariables("HTTP_RANGE"),7)  
  86.   if Range="" then  
  87.    Response.BinaryWrite(xml.responseBody)  
  88.   else  
  89.    S.position=Clng(Split(Range,"-")(0))  
  90.    Response.BinaryWrite(xml.responseBody)  
  91.   End if  
  92.   end if  
  93.  Response.End    
  94.    Set xml = Nothing  
  95. end function  
  96. '''''''''''''''''''''''''''''''''''''''''''''''''''''  
  97. %> 

最后此篇关于asp读取远程文件并保存到本地代码的文章就讲到这里了,如果你想了解更多关于asp读取远程文件并保存到本地代码的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com