手机
当前位置:查字典教程网 >编程开发 >ASP教程 >asp读取远程文件并保存到本地代码
asp读取远程文件并保存到本地代码
摘要:0)thenfileName=left(fileName,extPos-1)endifif(ifLogin=1)thencallPostHt...

<%

dimact,ifLogin,loginUrl,loginActUrl,loginData,fileUrl,fileName

act=request.QueryString("act")

if(act="do")then

ifLogin=Cint(request.QueryString("ifLogin"))

loginActUrl=request.Form("loginActUrl")

loginData=request.Form("loginData")

fileUrl=request.Form("fileUrl")

fileName=mid(fileUrl,instrrev(fileUrl,"/")+1)

extPos=instrrev(fileName,"?")

if(extPos>0)then

fileName=left(fileName,extPos-1)

endif

if(ifLogin=1)then

callPostHttpPage(loginActUrl,loginData)

endif

callDownloadFile(fileUrl,fileName)

else

%>

<formname="form1"method="post"action="?act=do">

<p>是否登录:

<inputname="ifLogin"type="radio"value="1">

<inputname="ifLogin"type="radio"value="0"checked>

否</p>

<p>登录提交地址:

<inputname="loginActUrl"type="text"size="50">

</p>

<p>

登录数据:<inputname="loginData"type="text"size="50">

</p>

<p>

要保存的远程文件URL:

<inputname="fileUrl"type="text"size="50">

</p>

<p>

<inputtype="submit"name="Submit"value="提交">

<inputtype="reset"name="Submit2"value="重写">

</p>

</form>

<%

endif

FunctionBytesToBstr(body,code)

dimobjstream

setobjstream=Server.CreateObject("adodb.stream")

objstream.Type=1

objstream.Mode=3

objstream.Open

objstream.Writebody

objstream.Position=0

objstream.Type=2

objstream.Charset=code

BytesToBstr=objstream.ReadText

objstream.Close

setobjstream=nothing

EndFunction

FunctionPostHttpPage(loginActUrl,PostData)

DimxmlHttp

DimRetStr

SetxmlHttp=CreateObject("Microsoft.XMLHTTP")

xmlHttp.Open"POST",loginActUrl,False

XmlHTTP.setRequestHeader"Content-Length",Len(PostData)

xmlHttp.setRequestHeader"Content-Type","application/x-www-form-urlencoded"

xmlHttp.SendPostData

IfErr.Number<>0Then

SetxmlHttp=Nothing

response.Write("提交登录时出错!提交数据:"&PostData)

ExitFunction

EndIf

PostHttpPage=BytesToBstr(xmlHttp.responseBody,"GB2312")

SetxmlHttp=nothing

EndFunction

'''''''''''''''''''''''''''''''''''''''''''

functionDownloadFile(url,filename)

Setxml=Server.CreateObject("Msxml2.XMLHTTP")'创建对象

xml.Open"GET",url,False

xml.Send'发送请求

ifErr.Number>0then

Response.Status="404"

else

Response.ContentType="application/octet-stream"

Response.AddHeader"Content-Disposition:","attachment;filename="&filename

Range=Mid(Request.ServerVariables("HTTP_RANGE"),7)

ifRange=""then

Response.BinaryWrite(xml.responseBody)

else

S.position=Clng(Split(Range,"-")(0))

Response.BinaryWrite(xml.responseBody)

Endif

endif

Response.End

Setxml=Nothing

endfunction

'''''''''''''''''''''''''''''''''''''''''''''''''''''

%>

【asp读取远程文件并保存到本地代码】相关文章:

ASP远程保存图片

读取目录下的文件得到一个数组

asp下tag的实现,简单介绍与部分代码

利用FSO取得图像文件信息

asp 查询数据代码

ASP读取IIS日志的小程序代码

asp中COM组件中如何连接数据库的代码

asp下实现替换远程文件为本地文件并保存远程文件的代码

asp文件上传:文件上传 源代码

asp实现读取数据库输出json代码

精品推荐
分类导航