c#取远程数据示例
我用的是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);
byte?? []?? returnData?? =?? wc.UploadData( "http://www.xxxx.com/aaa ",?? "POST ",?? postData);
string?? returnStr?? =?? Encoding.GetEncoding( "GB2312 ").GetString(returnData);
MessageBox.Show(returnStr);
}catch(Exception?? ex)
{
MessageBox.Show(ex.Message);
}
轉載于:https://www.cnblogs.com/netcorner/archive/2010/07/10/2911997.html
總結
- 上一篇: C++测试与调试知识
- 下一篇: NetBeans Weekly News