首页 > 编程 > .NET > 正文

老外编的程序(二)--System.Net的示例程序

2024-07-10 13:00:28
字体:
来源:转载
供稿:网友
using system;
using system.net;
using system.text;
using system.collections.specialized;

public class webclientsample
{
    public static void main()
    {
        try {
            
        // download the data to a buffer
               webclient client = new webclient();

          byte[] pagedata = client.downloaddata("http://www.microsoft.com");
        string pagehtml = encoding.ascii.getstring(pagedata);
        console.writeline(pagehtml);

        // download the data to a file
                client.downloadfile("http://www.bn.com", "page.htm");

        // upload some form post values
        namevaluecollection form = new namevaluecollection();        
        form.add("myname", "myvalue");        
        byte[] responsedata = client.uploadvalues("http://localhost/somefile.aspx", form);        

        }
        catch (webexception webex) {
              console.writeline(webex.tostring());
               if(webex.status == webexceptionstatus.connectfailure) {
                   console.writeline("are you behind a firewall?  if so, go through the proxy server.");
               }
        }
    }        
}
  • 本文来源于网页设计爱好者web开发社区http://www.html.org.cn收集整理,欢迎访问。
  • 发表评论 共有条评论
    用户名: 密码:
    验证码: 匿名发表