2016-08-05, 02:17 AM
Hey,
Why I need this is not really intresting but I do need it and I tried various methods but couldn't figure it out after my best but at the same time worst attempt since it uses WebClient. But I was really confident it should have work. But it didnt. How can I do this?
Current Code:
Why I need this is not really intresting but I do need it and I tried various methods but couldn't figure it out after my best but at the same time worst attempt since it uses WebClient. But I was really confident it should have work. But it didnt. How can I do this?
Current Code:
static void Main(string[] args)
{
var client = new CookieWebClient();
client.BaseAddress = @"{FORUMURL}";
var loginData = new NameValueCollection();
loginData.Add("username", "Coddr");
loginData.Add("password", "RIGHTPASSWORD");
client.UploadValues("member.php?action=login", "POST", loginData);
string htmlSource = client.DownloadString("index.php");
if (htmlSource.Contains("?action=logout"))
{
Console.WriteLine("You are logged in");
}
else
{
Console.WriteLine("You are logged out");
}
Console.ReadKey();
}
}
public class CookieWebClient : 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;
}
}