老外编的程序(二)--System.Net的示例程序-.Net技术-3P代码网
繁体中文
设为首页
加入收藏
当前位置:.Net技术首页 >> Asp.Net开发 >> 老外编的程序(二)--System.Net的示例程序

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

2007-07-15 08:00:00  作者:  来源:互联网  浏览次数:0  文字大小:【】【】【
简介: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...

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

}

}

}

}

责任编辑:admin
相关文章