How to login to wordpress programmatically?

前端 未结 8 1407
时光取名叫无心
时光取名叫无心 2020-12-24 04:14

I need to perform some action in wordpress admin panel programmatically but can\'t manage how to login to Wordpress using C# and HttpWebRequest.

Here is what I do:

8条回答
  •  南笙
    南笙 (楼主)
    2020-12-24 04:36

    TomerBu has the best answer for me, but something was missing.

    in his code, remplace :

     foreach (Cookie c in response.Cookies)
                Console.WriteLine(c.Name + " = " + c.Value);
    

    by

    if (response.Cookies != null)
        {
            foreach (Cookie currentcook in response.Cookies)
                 request.CookieContainer.Add(currentcook); //This is the key !!!
        }
    

    Next for futur request, you'll have to reuse CookieContainer.

提交回复
热议问题