天天看點

c#取遠端資料示例

< DOCTYPE html PUBLIC -WCDTD XHTML StrictEN httpwwwworgTRxhtmlDTDxhtml-strictdtd>

我用的是WebClient這個類來做的,如

try

{

WebClient   wc   =   new   WebClient();

wc.Headers.Add( "Content-Type ",   "application/x-www-form-urlencoded ");

wc.Headers.Add( "User-Agent ",   "Mozilla/4.0   (compatible;   MSIE   6.0;   Windows   NT   5.1;.NET   CLR   1.1.4322) ");

wc.Headers.Add( "Accept ",   "*/*) ");

string   postStr   =   "AAA=1&BBB=2 ";

byte   []   postData   =   Encoding.ASCII.GetBytes(postStr);

string   returnStr   =   Encoding.GetEncoding( "GB2312 ").GetString(returnData);

MessageBox.Show(returnStr);

}catch(Exception   ex)

MessageBox.Show(ex.Message);

}

<a href="http://enetcorner.blog.163.com/tag/c%23%E4%B8%93%E6%A0%8F/feeds">#c#專欄</a>

本文轉自 netcorner 部落格園部落格,原文連結: http://www.cnblogs.com/netcorner/archive/2010/07/10/2911997.html  ,如需轉載請自行聯系原作者