带有用户名&的HTTP GET / POST请求WinForm上的密码 [英] HTTP GET / POST Request with Username & Password on WinForm
本文介绍了带有用户名&的HTTP GET / POST请求WinForm上的密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过使用Get / Post方法获取我的用户名和密码的一些数据。
(对不起隐藏用户名和通行证)
I want to get some data with my username and password by using Get / Post method.
(Sorry for hiding username and pass)
CookieContainer cc = new CookieContainer();
String Username = "xxxxxx";
String PassWord = "xxxxxx";
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("http://212.175.170.218/edw/login.aspx");
byte[] byt = Encoding.UTF8.GetBytes("application=portal&url=http%3A%2F%2212.175.170.218%2edw%2login.aspx%3BtbUserName=" + Username + "%3DtbPassword=" + PassWord + "");
req.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705;)";
req.Method = "POST";
req.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
req.Headers.Add("Accept-Language: en-us,en;q=0.5");
req.Headers.Add("Accept-Encoding: gzip,deflate");
req.Headers.Add("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7");
req.KeepAlive = true;
req.Headers.Add("Keep-Alive: 300");
req.Referer = "http://212.175.170.218/edw/login.aspx";
req.CookieContainer = cc;
req.ContentLength = byt.Length;
req.ContentType = "application/x-www-form-urlencoded";
HttpWebResponse response = (HttpWebResponse)req.GetResponse();
cc.Add(response.Cookies);
Stream stm = response.GetResponseStream();
stm.Write(byt, 0, byt.Length);
StreamReader reader = new StreamReader(response.GetResponseStream());
string tmp = reader.ReadToEnd();
StreamWriter sw = new StreamWriter(req.GetRequestStream());
sw.Write("tbUserName=" + Username + "&tbPassword=" + PassWord + "&btnSend=Send");
sw.Close();
Stream stm = response.GetResponseStream();
stm.Write(byt, 0, byt.Length);
StreamReader reader = new StreamReader(response.GetResponseStream());
string tmp = reader.ReadToEnd();
我也在下面的链接上尝试了接受的答案:
http://stackoverflow.com/questions/14260905/http-get-请求用户名密码 [ ^ ]
但是当我尝试获取响应时字符串tmp返回登录页面的默认html源。 br />
我感谢任何帮助提前谢谢。
I also tried the accepted answer on the link below:
http://stackoverflow.com/questions/14260905/http-get-request-with-username-password[^]
But string tmp returns login page's default html source when i try to get Response.
I appreciate any help Thanks in advance.
推荐答案
下载Identity Server示例。如果你可以在你的工作中获得行业力量保护。
Download the Identity Server examples. If you can work it in you will gain industry strength protection.
这篇关于带有用户名&的HTTP GET / POST请求WinForm上的密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文