如何登录Wordpress管理仪表板?

时间:2017-01-26 19:53:55

标签: c# .net wordpress cookies

我尝试使用C#登录Wordpress管理信息中心。

public bool LogIn()
    {
        // webHelper is WebClient with cookies support (I can login on other sites with this class, even on Google)
        string siteHtmlSource = webHelper.DownloadStuff(PageUrl + "/wp-login.php");

        siteHtmlSource = webHelper.UploadStuff(PageUrl + "/wp-login.php",
            "log=" + HttpUtility.UrlEncode(UserName) + "&pwd=" + HttpUtility.UrlEncode(PassWord) +
            "&rememberme=forever&wp-submit=Log+In&redirect_to=" + HttpUtility.UrlEncode(PageUrl) +
            "%2Fwp-admin%2F&testcookie=1");

        if (!siteHtmlSource.Contains("Dashboard"))
        {
            loggedIn = false;
            return false;
        }

        loggedIn = true;
        return true;
    }

代码很简单,它适用于每个网站,甚至在Google上(当然也有不同的参数)。 发送POST后,我再次进入登录页面......

1 个答案:

答案 0 :(得分:0)

好吧,经过6个小时的思考,我编写了代码 WORKS (我可以通过WebClient下载管理仪表板页面(支持cookie))。它通过SSL连接,创建CookieContainer并将其放入WebClient(" WebHelper"在我的代码中)。

以下是代码:https://couponsgearbest.wordpress.com/2017/01/29/how-to-log-in-to-wordpress-dashboard-using-c-sharp-programming/