将WebBrowser的cookie信息传给HttpWebRequest
2010-12-28 22:33
267 查看
1、WebBrowser设置Cookie
1public partial class WebBrowserControl : Form
2 CookieContainer myCookieContainer = new CookieContainer();
2
3
4 //String 的Cookie 要转成 Cookie型的 并放入CookieContainer中
5 string cookieStr = webBrowser1.Document.Cookie;
6 string[] cookstr = cookieStr.Split(';');
7 foreach (string str in cookstr)
8
15 HttpWebRequest hreq = (HttpWebRequest)HttpWebRequest.Create("http://www.abc.com/search.asp");
16 hreq.Method = "POST";
17 hreq.ContentType = "application/x-www-form-urlencoded";
18
19 //自己创建的CookieContainer
20 hreq.CookieContainer = myCookieContainer;
21
22 string postdata = "id=2005&action=search&name=";
23 byte[] byte1 = Encoding.ASCII.GetBytes(postdata);
24 hreq.ContentLength = byte1.Length;
25
26 Stream poststream = hreq.GetRequestStream();
27 poststream.Write(byte1, 0, byte1.Length);
28 poststream.Close();
29
30 HttpWebResponse hres = (HttpWebResponse)hreq.GetResponse();
1public partial class WebBrowserControl : Form
2 CookieContainer myCookieContainer = new CookieContainer();
2
3
4 //String 的Cookie 要转成 Cookie型的 并放入CookieContainer中
5 string cookieStr = webBrowser1.Document.Cookie;
6 string[] cookstr = cookieStr.Split(';');
7 foreach (string str in cookstr)
8
15 HttpWebRequest hreq = (HttpWebRequest)HttpWebRequest.Create("http://www.abc.com/search.asp");
16 hreq.Method = "POST";
17 hreq.ContentType = "application/x-www-form-urlencoded";
18
19 //自己创建的CookieContainer
20 hreq.CookieContainer = myCookieContainer;
21
22 string postdata = "id=2005&action=search&name=";
23 byte[] byte1 = Encoding.ASCII.GetBytes(postdata);
24 hreq.ContentLength = byte1.Length;
25
26 Stream poststream = hreq.GetRequestStream();
27 poststream.Write(byte1, 0, byte1.Length);
28 poststream.Close();
29
30 HttpWebResponse hres = (HttpWebResponse)hreq.GetResponse();
相关文章推荐
- 将WebBrowser的cookie信息传给HttpWebRequest
- 将WebBrowser的cookie信息传给HttpWebRequest.
- 将WebBrowser的cookie信息传给HttpWebRequest
- C# WebBrowser HttpWebRequest Cookie 的结合运用。
- .Net中 webbrowser 和 httpwebrequest 共用 cookie
- 从WebBrowser中取得Cookie 和 HttpWebRequest设置cookie!
- 获取WebBrowser全cookie 和 httpWebRequest 异步获取页面数据
- 【转】C# WebRequest发起Http Post请求模拟登陆并cookie处理示例
- 使用HttpWebRequest提交ASP.NET表单并保持Session和Cookie
- HttpWebRequest post请求获取webservice void数据信息
- 利用HttpWebRequest和HttpWebResponse获取Cookie
- 使用HttpWebRequest提交ASP.NET表单并保持Session和Cookie
- HttpWebRequest客户端设置附加Cookie请求网页
- HttpWebRequest Cookie Bug 解决之道
- 如何将webbrowser控件的Cookie倒入CookieContainer供WebRequest使用
- 使用HttpWebRequest提交信息
- C#网页采集数据的几种方式(WebClient、WebBrowser和HttpWebRequest/HttpWebResponse)
- 集线程池应用、多次HttpWebRequest请求,自动切换账号等等的移动信息查询软件
- HttpWebRequest实现读取天气预报信息
- C# HttpWebRequest 绝技 根据URL地址获取网页信息