Ejemplo n.º 1
0
        public static bool Authenticate(string username, string password)
        {
            using (var webClient = new CookieWebClient(CookieContainer))
            {
                HttpWebResponse error;
                string          response = PostString(webClient, "http://oxidemod.org/login/login", new NameValueCollection
                {
                    { "login", username },
                    { "password", password }
                }, out error);

                if (error != null)
                {
                    throw new ApiResponseException(global::Nancy.HttpStatusCode.InternalServerError, error.StatusDescription);
                }

                var htmlDoc = new HtmlDocument();
                htmlDoc.LoadHtml(response);

                var rootNode    = htmlDoc.DocumentNode;
                var accountMenu = rootNode.SelectSingleNode("//*[@id=\"AccountMenu\"]");

                return(accountMenu != null);
            }
        }
Ejemplo n.º 2
0
 protected static string PostString(CookieWebClient webClient, string url, NameValueCollection values, out HttpWebResponse errorResponse)
 {
     return(TryAction(() =>
     {
         byte[] bytes = webClient.UploadValues(url, "POST", values);
         return Encoding.UTF8.GetString(bytes);
     }, out errorResponse));
 }
Ejemplo n.º 3
0
 protected static string DownloadString(CookieWebClient webClient, string url, out HttpWebResponse errorResponse)
 {
     return(TryAction(() => webClient.DownloadString(url), out errorResponse));
 }
Ejemplo n.º 4
0
 protected BaseApi()
 {
     WebClient = new CookieWebClient(CookieContainer);
 }