如何以编程方式登录MediaWiki网站 [英] How to login programmatically to mediawiki website

查看:83
本文介绍了如何以编程方式登录MediaWiki网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好:有一个使用MW 1.18.2构建的网站,该网站要求用户登录-否则,您将无法访问该页面中的任何页面.我具有有效的凭据可以从浏览器手动登录,但是我需要能够从Windows窗体应用程序(C#)进行相同的操作:当用户单击按钮时,我必须显示(或导航至)网站上的某些页面,为此,我必须先以编程方式登录.我已经在PHP和JScript中找到了示例,但是作为该网络人员的新手,我不知道如何使用它们,而且我不确定它们是否可以在客户端使用.

Hello There is a website built with MW 1.18.2, which requires users to log in - without this you cannot access any page in it. I have valid credentials to log in manually from browser, but I need to be able to do the same from my windows forms application (C#): when user clicks on a button I have to show (or navigate to) certain page from the website, and for that I have to login programmatically first. I have found the examples in PHP and JScript but being newbie in that web staff I have no idea how to use them, and I am not sure they can be used on client side.

任何帮助将不胜感激.

推荐答案

谢谢LeoR,它的工作原理是:

Thank you LeoR, it works:

private void buttonLoginAndShowMainPage_Click(object sender, EventArgs e)
    {
        this.webBrowser1.Navigate(mediawikisite);
    }

    private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        HtmlDocument doc = this.webBrowser1.Document;

        HtmlElement LoginForm = doc.Forms[0];
        HtmlElement UserName = doc.GetElementById("wpName1");
        HtmlElement Password = doc.GetElementById("wpPassword1");

        UserName.SetAttribute("value", "myuserid");
        Password.SetAttribute("value", "mypassword");

        LoginForm.InvokeMember("submit");
    }

这篇关于如何以编程方式登录MediaWiki网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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