The question is clear I hope. I want log in to DeviantArt through my application and I found stuff but it just doesn't seem to work... Here's my code(running in a thread):
//===========================================
// Login
//===========================================
string formUrl = "https://www.deviantart.com/users/login";
string formParams = string.Format("login-username={0}&login-password={1}", "mai username", "mai password");
string cookieHeader;
System.Net.WebRequest req = System.Net.WebRequest.Create(formUrl);
req.ContentType = "application/x-www-form-urlencoded";
req.Method = "POST";
byte[] bytes = Encoding.ASCII.GetBytes(formParams);
req.ContentLength = bytes.Length;
using (Stream os = req.GetRequestStream())
{
os.Write(bytes, 0, bytes.Length);
}
//=========Send Cookie=============
System.Net.WebResponse resp = req.GetResponse();
cookieHeader = resp.Headers["Set-cookie"];
string pageSource;
using (StreamReader sr = new StreamReader(resp.GetResponseStream()))
{
pageSource = sr.ReadToEnd();
}
string getUrl = "http://www.deviantart.com/users/loggedin";
System.Net.WebRequest getRequest = System.Net.WebRequest.Create(getUrl);
getRequest.Headers.Add("Cookie", cookieHeader);
System.Net.WebResponse getResponse = getRequest.GetResponse();
I get a 403 error at the last line where I'm trying to get response. Some information about DeviantArt: 1: You can access pages etc. but you can't comment or anything. 2: When I tried to check if deviantart.com existed it gave me a 403 no permission error so that's why I'm trying to log in. When I write pageSource to a textfile I get this. What do I do wrong and how do I fix it? because I really have no clue why this isn't working...
PS: Alternate ways to do this are also welcome except Selenium