使用asp.net C#自动登录外部网站 [英] Auto Login to External Website using asp.net C#

查看:50
本文介绍了使用asp.net C#自动登录外部网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨。



我有网站的用户名,密码和网址。我想自动登录网站。我用谷歌搜索但无法得到解决方案。也使用POST,WebRequest但无法登录。有人可以帮忙并发给我代码吗?

Hi.

I have the username, password and url of the website. I want to login into the website automatically. I googled it but could not get the solution. Also used POST, WebRequest but couldn't log in. Could anyone please help and send me the code?

推荐答案

嗨Sandip,我是ASP的新手。 net我只是阅读了代码并尝试通过相同的方式自动化我的webmail登录,而我正在获得401.



你能建议我,我需要在哪里工作,也有任何其他网络方法的帮助,比如我以前使用(用于登录自动化的表单中的Web浏览器控件)会很有帮助。



谢谢





Hi Sandip , I am a new bie in ASP .net i just read through the code and tried to automate my webmail login via same, while i am getting 401 .

Could you please suggest me , where do i need to work on , also any help on other web methods , like i used to work with (web browser control in forms for login automation) would be much helpful.

Thank you


<pre>



Uri uri1 = new Uri(https://webmail.abc.com);



string strPostData = String.Format(username = {0}& ; password = {1},username,passw123);

HttpWebRequest webreq1 = WebRequest.Create(uri1)as HttpWebRequest;

webreq1.Method =发布;

webreq1.ContentLength = strPostData.Length;

webreq1.ContentType =application / x-www-form-urlencoded;



CookieContainer cookieContainer = new CookieContainer();

webreq1.CookieContainer = cookieContainer;



StreamWriter web1_p = new StreamWriter(webreq1.GetRequestStream());

web1_p.Write(strPostData);

web1_p.Close();



HttpWebResponse Hr_resp =(HttpWebResponse)webreq1.GetResponse();

StreamReader sr_reader = new StreamReader(Hr_resp.GetResponseStream());

string weba = sr_reader.ReadToEnd();

TextBox1.Text = Andz.ToString();

sr_reader.Close();


Uri uri1=new Uri("https://webmail.abc.com");

string strPostData = String.Format("username={0}&password={1}", "username", "passw123");
HttpWebRequest webreq1=WebRequest.Create(uri1) as HttpWebRequest;
webreq1.Method = "post";
webreq1.ContentLength = strPostData.Length;
webreq1.ContentType = "application/x-www-form-urlencoded";

CookieContainer cookieContainer = new CookieContainer();
webreq1.CookieContainer = cookieContainer;

StreamWriter web1_p = new StreamWriter(webreq1.GetRequestStream());
web1_p.Write(strPostData);
web1_p.Close();

HttpWebResponse Hr_resp = (HttpWebResponse)webreq1.GetResponse();
StreamReader sr_reader = new StreamReader(Hr_resp.GetResponseStream());
string weba = sr_reader.ReadToEnd();
TextBox1.Text = Andz.ToString();
sr_reader.Close();


这篇关于使用asp.net C#自动登录外部网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆