-1
我想通過C#應用程序登錄到我的Drupal站點,並且一直在使用OAuth和服務,但沒有成功。有沒有辦法從C#登錄會話?我需要這樣做來訪問我的Drupal站點上的私人文件。通過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");