ASP.NET实现HTTP方式获取功能

1@ Assembly Name="System.Net" 
1@ Import Namespace="System.Net" 
1@ Import Namespace="System.IO" 
 1<script language="VB" runat="server">   
 2dim STRtemp as string   
 3Sub Page_Load(Src As Object, E As EventArgs)   
 4Dim HttpWResp as HTTPWebresponse   
 5Dim sr As StreamReader   
 6'dim STRtemp as string   
 7dim build as new stringbuilder   
 8  
 9HttpWReq = WebRequestFactory.Create("http://www.funinspace.com")   
10HttpWReq.KeepAlive = false   
11HttpWResp = HttpWReq.GetResponse()   
12sr = new StreamReader(HttpWResp.GetResponseStream(), Encoding.ASCII)   
13  
14Try   
15line=sr.ReadLine()   
16lineENC = server.HTMLencode(line) & vbcrlf & "<br>"   
17build.append (lineENC)   
18  
19do while not IsNothing(line)   
20line = sr.ReadLine()   
21lineENC = server.HTMLencode(line) & vbcrlf & "<br>"   
22build.append (lineENC)   
23loop   
24Catch ex As Exception   
25problem.text =ex.Message   
26End Try   
27  
28labelscrape.text=build.ToString()   
29End Sub   
30</script>
 1<html><head>
 2<title>Scraping A Website</title>
 3</head>
 4<body bgcolor="#FFFFFF">
 5<h3><font face="Verdana">Scraped Data</font></h3>
 6<asp:label id="problem" runat="server"></asp:label>
 7<font face="courier new" size="2">
 8<asp:label id="labelscrape" runat="server"></asp:label>
 9</font>
10</body></html>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus