解决方案 »
- VS2008 自定义模板问题“未将对象引用设置到对象的实例”
- 【求助】权限树问题
- 病理图文分析系统(液基细胞)
- C#合并EXCEL单元格
- 能不能阻止事件的冒泡
- 请教高手,如何从数据库中读取rtf格式(带图片)的blob字段显示在网页的控件(类似于c#的richtextbox)中?
- C#如何读写DBF文件,在线等...
- 关于处理用户请求的问题!(asp.net C#)
- 有哪位兄弟能把vs.net2003安装后的文件夹Microsoft Visual Studio .NET 2003下的文件和文件夹的功能作一个详细的分析,谢谢了
- Visio与vs2005自带的“类关系图”功能哪个更好?好在哪里?
- 医院管理系统
- 小弟做了个浏览器,如何实现鼠标拖动超链接打开新网页?
参考
//在WebBrowser中登录 cookie保存在 WebBrowser.Document.Cookie中
CookieContainer myCookieContainer = new CookieContainer();
//String 的Cookie 要转成 Cookie型的 并放入CookieContainer中
string cookieStr = webBrowser1.Document.Cookie;
string[] cookstr = cookieStr.Split(';');
foreach (string str in cookstr)
{
string[] cookieNameValue = str.Split('=');
Cookie ck = new Cookie(cookieNameValue[0].Trim().ToString(), cookieNameValue[1].Trim().ToString());
ck.Domain = "www.abc.com";//必须写对
myCookieContainer.Add(ck);
}
HttpWebRequest hreq = (HttpWebRequest)HttpWebRequest.Create("http://www.abc.com/search.asp");
hreq.Method = "POST";
hreq.ContentType = "application/x-www-form-urlencoded";
//自己创建的CookieContainer
hreq.CookieContainer = myCookieContainer;
string postdata = "id=2005&action=search&name=";
byte[] byte1 = Encoding.ASCII.GetBytes(postdata);
hreq.ContentLength = byte1.Length;
Stream poststream = hreq.GetRequestStream();
poststream.Write(byte1, 0, byte1.Length);
poststream.Close();
HttpWebResponse hres = (HttpWebResponse)hreq.GetResponse();