我想通过 C# 应用程序登录到我的 Drupal 站点,并且一直在使用 OAuth 和服务但没有成功。有没有办法通过 C# 会话登录?我需要这样做才能访问我的 Drupal 站点上的私人文件。
我尝试在stackoverflow上使用来自用户的以下代码,现在成功了。使用代码时我得到 403。
public class CookieAwareWebClient : WebClient
{
private CookieContainer cookie = new CookieContainer();
protected override WebRequest GetWebRequest(Uri address)
{
WebRequest request = base.GetWebRequest(address);
if (request is HttpWebRequest)
{
(request as HttpWebRequest).CookieContainer = cookie;
}
return request;
}
}
var client = new CookieAwareWebClient();
client.BaseAddress = @"https://www.mysite.com/";
var loginData = new NameValueCollection();
loginData.Add("login", user);
loginData.Add("password", password);
client.UploadValues("login.php", "POST", loginData); // ERROR HERE
//Now you are logged in and can request pages
string htmlSource = client.DownloadString("index.php");