C#应用程序登录到Joomla [英] c# application login to joomla
本文介绍了C#应用程序登录到Joomla的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要连接到该网站(2.5的Joomla)的管理面板。我的问题是非常相似,这话题,但我还没有找到解决办法,所以我期待您的帮助。
I need to connect to the admin panel of the site (Joomla 2.5). My question is very similar to this topic, but I have not found the solution, so am looking for your help.
下面是我的示例代码:
WebClient Client = new WebClient();
System.Collections.Specialized.NameValueCollection Collection =
new System.Collections.Specialized.NameValueCollection();
Collection.Add("username", "--my username--");
Collection.Add("passwd", "--my password--");
Collection.Add("option", "com_login");
Collection.Add("lang", "");
Collection.Add("task", "login");
//I find the token
byte[] res = Client.UploadValues("http://mysite/administrator/index.php", "POST", Collection);
string source = Encoding.UTF8.GetString(res, 0, res.Length);
Regex regex = new Regex("([a-zA-z0-9]{32})")
Match match = regex.Match(source);
if (match.Success)
string token = match.Value;
//add token value to collection (example value 3e2aedd3de46f8a55ec15a6eb58e1c19)
Collection.Add(token, "1");
//run authorization
byte[] res = Client.UploadValues("http://mysite/administrator/index.php", "POST", Collection);
string source = Encoding.UTF8.GetString(res, 0, res.Length);
//in the row, the other token (example 06f1740ef6d6e87ae004500edddd7d7d)
但事实并非如此工作。在源不等于价值令牌令牌值。我在做什么错了?
But it does not work. A token value in the "source" not equal value "token". What am I doing wrong?
推荐答案
Web客户端是不是最好的方式,当你试图模仿网站的行为。使用HttpWebRequest和HttpWebResponse来代替。并设置为保持活动请求的连接属性。
WebClient isn't the best way when you try to mimic a website behavior. Use HttpWebRequest and HttpWebResponse instead. And set the Connection property of the request to "Keep-alive".
这篇关于C#应用程序登录到Joomla的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文