asp读取远程文件并保存到本地代码_ASP教程-查字典教程网
asp读取远程文件并保存到本地代码
asp读取远程文件并保存到本地代码
发布时间:2016-12-29 来源:查字典编辑
摘要: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教程学习
    编程开发子分类