//取得动态文件内容
Title
1 Function GetHttpPage(HttpUrl, Coding)
2 On Error Resume Next
3 If IsNull(HttpUrl) = True Or Len(HttpUrl) < 18 Or HttpUrl = "" Then
4 GetHttpPage = ""
5 Exit Function
6 End If
7 Dim Http
8 Set Http = Server.CreateObject("MSXML2.XMLHTTP")
9 Http.Open "GET", HttpUrl, False
10 Http.Send
11 If Http.Readystate <> 4 Then
12 GetHttpPage = ""
13 Exit Function
14 End If
15 If Coding = 1 Then
16 GetHttpPage = BytesToBstr(Http.ResponseBody, "UTF-8")
17 ElseIf Coding = 2 Then
18 GetHttpPage = BytesToBstr(Http.ResponseBody, "Big5")
19 Else
20 GetHttpPage = BytesToBstr(Http.ResponseBody, "GB2312")
21 End If
22
23 Set Http = Nothing
24 If Err.Number <> 0 Then
25 Err.Clear
26 End If
27 End Function
28
29
30 Function BytesToBstr(Body, Cset)
31 Dim Objstream
32 Set Objstream = Server.CreateObject("adodb.stream")
33 Objstream.Type = 1
34 Objstream.Mode = 3
35 Objstream.Open
36 Objstream.Write Body
37 Objstream.Position = 0
38 Objstream.Type = 2
39 Objstream.Charset = Cset
40 BytesToBstr = Objstream.ReadText
41 Objstream.Close
42 Set Objstream = Nothing
43 End Function
2 On Error Resume Next
3 If IsNull(HttpUrl) = True Or Len(HttpUrl) < 18 Or HttpUrl = "" Then
4 GetHttpPage = ""
5 Exit Function
6 End If
7 Dim Http
8 Set Http = Server.CreateObject("MSXML2.XMLHTTP")
9 Http.Open "GET", HttpUrl, False
10 Http.Send
11 If Http.Readystate <> 4 Then
12 GetHttpPage = ""
13 Exit Function
14 End If
15 If Coding = 1 Then
16 GetHttpPage = BytesToBstr(Http.ResponseBody, "UTF-8")
17 ElseIf Coding = 2 Then
18 GetHttpPage = BytesToBstr(Http.ResponseBody, "Big5")
19 Else
20 GetHttpPage = BytesToBstr(Http.ResponseBody, "GB2312")
21 End If
22
23 Set Http = Nothing
24 If Err.Number <> 0 Then
25 Err.Clear
26 End If
27 End Function
28
29
30 Function BytesToBstr(Body, Cset)
31 Dim Objstream
32 Set Objstream = Server.CreateObject("adodb.stream")
33 Objstream.Type = 1
34 Objstream.Mode = 3
35 Objstream.Open
36 Objstream.Write Body
37 Objstream.Position = 0
38 Objstream.Type = 2
39 Objstream.Charset = Cset
40 BytesToBstr = Objstream.ReadText
41 Objstream.Close
42 Set Objstream = Nothing
43 End Function
url="http://www.cnblogs.com/ly312/1.asp" //查看的地址
mailbody=GetHttpPage(url,4) //取得内容
tnow = now()
fname = year(tnow)
fname = fname & ".html" '生成HTML文件的文件名
filehtml="resume" //保存的文件夹位置
path = Server.MapPath(filehtml) '保存路径
Set fso = CreateObject("Scripting.FileSystemObject")
Set fhtml = fso.CreateTextFile(path&"\"&fname)
fhtml.WriteLine mailbody '保存文件
fhtml.Close
files=filehtml&"\"&fname
%>
<%
call downloadFile(files)
//下载文件程序
Title
1 Function downloadFile(strFile)
2 strFilename = server.MapPath(strFile)
3 'strFilename = strFile
4 ' clear the buffer
5 Response.Buffer = True
6 Response.Clear
7
8 Set s = Server.CreateObject("ADODB.Stream")
9 s.Open
10 s.Type = 1
11 on error resume next
12 Set fso = Server.CreateObject("Scripting.FileSystemObject")
13 if not fso.FileExists(strFilename) then
14 Response.Write("<h1>Error:</h1>" & strFilename & " 文件不存在<p>")
15 Response.End
16 end if
17 Set f = fso.GetFile(strFilename)
18 intFilelength = f.size
19 s.LoadFromFile(strFilename)
20 if err then
21 Response.Write("<h1>Error: </h1>文件下载错误 <p>")
22 Response.End
23 end if
24 Response.AddHeader "Content-Disposition", "attachment; filename=1.doc" //默认下载文件名,这地方我默认写doc文档
25 Response.AddHeader "Content-Length", intFilelength
26 Response.CharSet = "gb2312"
27 Response.ContentType = "application/octet-stream"
28
29
30 Response.BinaryWrite
31 s.Read
32 Response.Flush
33 s.Close
34 Set s = Nothing
35
36 End Function
2 strFilename = server.MapPath(strFile)
3 'strFilename = strFile
4 ' clear the buffer
5 Response.Buffer = True
6 Response.Clear
7
8 Set s = Server.CreateObject("ADODB.Stream")
9 s.Open
10 s.Type = 1
11 on error resume next
12 Set fso = Server.CreateObject("Scripting.FileSystemObject")
13 if not fso.FileExists(strFilename) then
14 Response.Write("<h1>Error:</h1>" & strFilename & " 文件不存在<p>")
15 Response.End
16 end if
17 Set f = fso.GetFile(strFilename)
18 intFilelength = f.size
19 s.LoadFromFile(strFilename)
20 if err then
21 Response.Write("<h1>Error: </h1>文件下载错误 <p>")
22 Response.End
23 end if
24 Response.AddHeader "Content-Disposition", "attachment; filename=1.doc" //默认下载文件名,这地方我默认写doc文档
25 Response.AddHeader "Content-Length", intFilelength
26 Response.CharSet = "gb2312"
27 Response.ContentType = "application/octet-stream"
28
29
30 Response.BinaryWrite
31 s.Read
32 Response.Flush
33 s.Close
34 Set s = Nothing
35
36 End Function
%>