如果网站是用GET而不是POST,该如何模拟登陆它呀? Post方式的主要是得到CookieContainer,然后在登陆的时候附加上它就OK了,现在发现对于Get方式的,却无效,老是提示Cannot send a content-body with this verb-type 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 HttpWebRequest是支持Get Post方式的看看你的参数是不是写错了 request.ContentType = "application/x-www-form-urlencoded";比如这个Type只能再Post中用再Get中去掉这一行 应该没问题,你的代码? *****************************************************************************欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) 最新版本:20070212http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html 有劳楼上仁兄帮看看 private void Form1_Load(object sender, EventArgs e) { string url = "http://www.abc.com/loginGr.jsp"; string username = "105"; string password = "221"; Login_job12333(url,username,password,Get_cookiecontainer(url)); } public CookieContainer Get_cookiecontainer(string url) { CookieContainer c1 = new CookieContainer(); HttpWebRequest rq1 = (HttpWebRequest)WebRequest.Create(url); rq1.CookieContainer = new CookieContainer(); HttpWebResponse rp1 = (HttpWebResponse)rq1.GetResponse(); c1 = rq1.CookieContainer; return c1; } public void Login_job12333(string url, string username, string password, CookieContainer cc) { HttpWebRequest rq1 = (HttpWebRequest)WebRequest.Create(url); rq1.Referer = url; rq1.AllowAutoRedirect = true; rq1.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)"; rq1.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */*"; rq1.Method = "GET"; rq1.CookieContainer = cc; string s03 = "aaa/login.jsp?" + "cme=v1&zjhm=" + username + "&password=" + password; byte[] b1 = Encoding.GetEncoding("GB2312").GetBytes(s03); rq1.ContentLength = b1.Length; Stream sw1 = rq1.GetRequestStream(); sw1.Write(b1, 0, b1.Length); sw1.Close(); HttpWebResponse rp1 = (HttpWebResponse)rq1.GetResponse(); Stream rc1 = rp1.GetResponseStream(); StreamReader read1 = new StreamReader(rc1, System.Text.Encoding.Default); string s1 = read1.ReadToEnd(); read1.Close(); rp1.Close(); } 不用设置ContentLength 直接用url= "http://www.abc.com/aaa/login.jsp?" + "cme=v1&zjhm=" + username + "&password=" + password; feiyun0112兄弟提醒得好我直接在浏览器中输入http://www.abc.com/aaa/login.jsp?" + "cme=v1&zjhm=" + username + "&password=" + password可以进入的问题是,我 HttpWebRequest rq1 = (HttpWebRequest)WebRequest.Create(url); rq1.AllowAutoRedirect = true; HttpWebResponse rp1 = (HttpWebResponse)rq1.GetResponse();确提示404错误找不到server 谢谢,我给你发csdn短信息了,请查收 解决了,谢谢feiyun0112(http://feiyun0112.cnblogs.com/) 老师!!直接reques,response不行,还得附加上cookiecontainer! C#,winform进制转换问题 字符串问题 pread的标签页 解决即送50分,十分满意就再加50分,各位请进来看看!~ 请教一个有关字符串处理的文件格式转换问题 ? 谁有winform下面的outlook风格的控件啊? sql 2000统计天数 请高手帮忙(winform datagrid dataset) [求助]DataGridView进行单元格数据验证时,如何获得原数据? ref,in.out的区别,::是否还保留? 做人要厚道,讨论要理智 一个关于C/S CLIENT多线程中FORM的问题
看看你的参数是不是写错了
比如这个Type只能再Post中用
再Get中去掉这一行
*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) 最新版本:20070212http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html
{
string url = "http://www.abc.com/loginGr.jsp";
string username = "105";
string password = "221";
Login_job12333(url,username,password,Get_cookiecontainer(url));
}
public CookieContainer Get_cookiecontainer(string url)
{
CookieContainer c1 = new CookieContainer();
HttpWebRequest rq1 = (HttpWebRequest)WebRequest.Create(url);
rq1.CookieContainer = new CookieContainer();
HttpWebResponse rp1 = (HttpWebResponse)rq1.GetResponse();
c1 = rq1.CookieContainer;
return c1;
}
public void Login_job12333(string url, string username, string password, CookieContainer cc)
{
HttpWebRequest rq1 = (HttpWebRequest)WebRequest.Create(url);
rq1.Referer = url;
rq1.AllowAutoRedirect = true;
rq1.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)";
rq1.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */*";
rq1.Method = "GET";
rq1.CookieContainer = cc;
string s03 = "aaa/login.jsp?" + "cme=v1&zjhm=" + username + "&password=" + password;
byte[] b1 = Encoding.GetEncoding("GB2312").GetBytes(s03);
rq1.ContentLength = b1.Length;
Stream sw1 = rq1.GetRequestStream();
sw1.Write(b1, 0, b1.Length);
sw1.Close();
HttpWebResponse rp1 = (HttpWebResponse)rq1.GetResponse(); Stream rc1 = rp1.GetResponseStream();
StreamReader read1 = new StreamReader(rc1, System.Text.Encoding.Default);
string s1 = read1.ReadToEnd();
read1.Close();
rp1.Close();
}
直接用url= "http://www.abc.com/aaa/login.jsp?" + "cme=v1&zjhm=" + username + "&password=" + password;
我直接在浏览器中输入http://www.abc.com/aaa/login.jsp?" + "cme=v1&zjhm=" + username + "&password=" + password可以进入的
问题是,我 HttpWebRequest rq1 = (HttpWebRequest)WebRequest.Create(url);
rq1.AllowAutoRedirect = true;
HttpWebResponse rp1 = (HttpWebResponse)rq1.GetResponse();
确提示404错误找不到server
直接reques,response不行,还得附加上cookiecontainer!