<%
Dim act, 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, limit Rev (fileurl, "/") + 1)
Extpos = Limit Rev (filename ,"? ")
If (extpos> 0) then
Filename = left (filename, extPos-1)
End if
If (iflogin = 1) then
Call posthttppage (loginacturl, logindata)
End if
Call downloadfile (fileurl, filename)
Else
%>
<Form name = "form1" method = "Post" Action = "? Act = Do ">
<P> logon or not:
<Input name = "iflogin" type = "radio" value = "1">
Yes
<Input name = "iflogin" type = "radio" value = "0" Checked>
No </P>
<P> logon submission address:
<Input name = "loginacturl" type = "text" size = "50">
</P>
<P>
Logon data: <input name = "logindata" type = "text" size = "50">
</P>
<P>
The URL of the remote file to save:
<Input name = "fileurl" type = "text" size = "50">
</P>
<P>
<Input type = "Submit" name = "Submit" value = "Submit">
<Input type = "reset" name = "submit2" value = "Rewrite">
</P>
</Form>
<%
End if
Function bytestobstr (body, code)
Dim objstream
Set objstream = server. Createobject ("ADODB. Stream ")
Objstream. type = 1
Objstream. mode = 3
Objstream. Open
Objstream. Write body
Objstream. Position = 0
Objstream. type = 2
Objstream. charset = Code
Bytestobstr = objstream. readtext
Objstream. Close
Set objstream = nothing
End Function
Function posthttppage (loginacturl, postdata)
Dim XMLHTTP
Dim retstr
Set XMLHTTP = Createobject ("Microsoft. XMLHTTP ")
XMLHTTP. Open "Post", loginacturl, false
XMLHTTP. setRequestHeader "Content-Length", Len (postdata)
XMLHTTP. setRequestHeader "Content-Type", "application/X-WWW-form-urlencoded"
XMLHTTP. Send postdata
If err. Number <> 0 then
Set XMLHTTP = nothing
Response. Write ("An error occurred while submitting logon! Submit data: "& postdata)
Exit Function
End if
Posthttppage = bytestobstr (XMLHTTP. responsebody, "gb2312 ")
Set XMLHTTP = nothing
End Function
'''''''''''''''''''''''''''''''''''''''' '''
Function downloadfile (URL, filename)
Set xml = server. Createobject ("msxml2.xmlhttp") 'create an object
XML. Open "get", URL, false
XML. Send' send request
If err. number> 0 then
response. status = "404"
else
response. contenttype = "application/octet-stream"
response. addheader "content-Disposition:", "attachment; filename =" & filename
range = mid (request. servervariables ("http_range"), 7)
If range = "" Then
response. binarywrite (XML. responsebody)
else
S. position = clng (split (range, "-") (0)
response. binarywrite (XML. responsebody)
end if
response. end
set xml = nothing
end function
'''''''''''''''''''''''' '''
%>