欢迎光临
我们一直在努力

老外编的程序(二)--System.Net的示例程序-.NET教程,C#语言

建站超值云服务器,限时71元/月

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.");
               }
        }
    }        
}

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 老外编的程序(二)--System.Net的示例程序-.NET教程,C#语言
分享到: 更多 (0)