public RedditLoginData Login(string username, string password) { var uri = "http://www.reddit.com/api/login/" + username; var parameters = string.Format("user={0}&passwd={1}&api_type=json", username, password); var response = HttpPost(uri, parameters); var loginData = new RedditLoginData(); if (response.Contains("modhash")) { //example response from a successful login //"{\"json\": {\"errors\": [], \"data\": {\"modhash\": \"5kdh1o3k950c5e71ff91152eea871995a12922c7b2e873e951\", \"cookie\": \"15777892,2012-10-23T22:16:39,3637e3b20aa62fe0c1fc974f6f54e0b14e982441\"}}}" var index = response.IndexOf("{\"modhash\":"); var sub = response.Substring(index, response.Length - index - 2); loginData = JsonConvert.DeserializeObject <RedditLoginData>(sub); } return(loginData); }
public RedditLoginData Login(string username, string password) { var uri = "http://www.reddit.com/api/login/" + username; var parameters = string.Format("user={0}&passwd={1}&api_type=json", username, password); var response = HttpPost(uri, parameters); var loginData = new RedditLoginData(); if (response.Contains("modhash")) { //example response from a successful login //"{\"json\": {\"errors\": [], \"data\": {\"modhash\": \"5kdh1o3k950c5e71ff91152eea871995a12922c7b2e873e951\", \"cookie\": \"15777892,2012-10-23T22:16:39,3637e3b20aa62fe0c1fc974f6f54e0b14e982441\"}}}" var index = response.IndexOf("{\"modhash\":"); var sub = response.Substring(index, response.Length - index - 2); loginData = JsonConvert.DeserializeObject<RedditLoginData>(sub); } return loginData; }