如何使用httpcode发起get请求
HttpCode使用篇使用HttpCode时,请先引用 System.Web
Framework 4.0 时需要引用System.Web.Extensions
使用httpcode发起get请求
方法一: 使用HttpHelpers类获取结果
string url = "bbs.msdn5.com";//请求地址
string res = string.Empty;//请求结果,请求类型不是图片时有效
System.Net.CookieContainer cc = new System.Net.CookieContainer();//自动处理Cookie对象
HttpHelpers helper = new HttpHelpers();//发起请求对象
HttpItems items = new HttpItems();//请求设置对象
HttpResults hr = new HttpResults();//请求结果
items.URL = url; //设置请求地址
items.Container = cc;//自动处理Cookie时,每次提交时对cc赋值即可
hr = helper.GetHtml(items);//发起请求
res = hr.Html;//得到请求结果
方法二: 使用Wininet类获取结果
string url = "bbs.msdn5.com";//请求地址
string res = string.Empty;//请求结果,请求类型不是图片时有效
Wininet wnet = new Wininet();
res = wnet.GetHtmlByWininetUTF8(url);//以UTF8的编码方式得到结果
//res=wnet.GetData(url);以gbk编码的方式得到结果
方法三: 使用XJHTTP类获取结果
string BaseUrl = "msdn5.com";//设置请求的地址
XJHTTP xjhttp = new XJHTTP();
CookieContainer cc = new CookieContainer(); //请求自动处理cookie
HttpResults hr = xjhttp.GetHtml(BaseUrl, cc);//发起请求
txtInfo.Text = hr.Html;//得到请求对象
三种方式说明
方法一;比较灵活;(推荐使用)
方法二则是与IE一样,使用底层API;
方法三则是提供懒人方法
是提供懒人方法
页:
[1]