首页 > 编程 > .NET > 正文

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

2024-07-10 12:57:56
字体:
来源:转载
供稿:网友
<%@ assembly name="system.net" %>
<%@ import namespace="system.net" %>
<%@ import namespace="system.io" %>
<script language="vb" runat="server">
dim strtemp as string
sub page_load(src as object, e as eventargs)
    dim httpwresp as httpwebresponse
    dim sr as streamreader
    'dim strtemp as string
    dim build as new stringbuilder

    httpwreq = webrequestfactory.create("http://www.funinspace.com")
    httpwreq.keepalive = false
    httpwresp = httpwreq.getresponse()
    sr = new streamreader(httpwresp.getresponsestream(), encoding.ascii)
    
    try
     line=sr.readline()
     lineenc = server.htmlencode(line) & vbcrlf & "<br>"
     build.append (lineenc)

    do while not isnothing(line)
         line = sr.readline()
            lineenc = server.htmlencode(line) & vbcrlf & "<br>"
            build.append (lineenc)
    loop
    catch ex as exception
        problem.text =ex.message
    end try
    
    labelscrape.text=build.tostring()
end sub
</script>
<html><head>
<title>scraping a website</title>
</head>
<body bgcolor="#ffffff">
<h3><font face="verdana">scraped data</font></h3>
    <asp:label id=problem runat="server"/>

    <font face="courier new" size="2">
        <asp:label id=labelscrape runat="server"/>
    </font>
</body></html>
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表