public static void Test_Md5_01(string text) { //string hash = GetMd5Hash(text); string hash = Crypt.ComputeMD5Hash(text).zToHex(lowercase: true); Trace.WriteLine("text : \"{0}\"", text); Trace.WriteLine("MD5 hash : \"{0}\"", hash); }
public static Http Login(XXElement xeSource) { XmlConfig localConfig = new XmlConfig(XmlConfig.CurrentConfig.GetExplicit("LocalConfig")); string login = localConfig.GetExplicit("DownloadAutomateManager/Ebookdz/Login"); //string hashPassword = Crypt.ComputeMD5Hash(localConfig.GetExplicit("DownloadAutomateManager/Ebookdz/Password")); string hashPassword = Crypt.ComputeMD5Hash(localConfig.GetExplicit("DownloadAutomateManager/Ebookdz/Password")).zToHex(lowercase: true); // <base href="http://www.ebookdz.com/forum/" /> string urlBase = xeSource.XPathValue("//head//base/@href"); //string urlBase = xeSource.XPathValue("//body//base/@href"); //Trace.WriteLine("urlBase : \"{0}\"", urlBase); XXElement xeForm = xeSource.XPathElement("//form[@id='navbar_loginform']"); if (xeForm.XElement == null) { //Trace.WriteLine("element not found \"//form[@id='navbar_loginform']\""); throw new PBException("element form not found \"//form[@id='navbar_loginform']\""); } //Trace.WriteLine("form action : \"{0}\"", xeForm.XPathValue("@action")); string urlForm = zurl.GetUrl(urlBase, xeForm.XPathValue("@action")); string method = xeForm.XPathValue("@method"); //Trace.WriteLine("urlForm : \"{0}\" method {1}", urlForm, method); StringBuilder sb = new StringBuilder(); bool first = true; foreach (XXElement xeInput in xeForm.XPathElements(".//input")) { string name = xeInput.XPathValue("@name"); if (name == null) { continue; } string value = null; if (name == "vb_login_username") { value = login; } else if (name == "vb_login_password") { value = null; } else if (name == "vb_login_md5password" || name == "vb_login_md5password_utf") { value = hashPassword; } else { value = xeInput.XPathValue("@value"); } if (!first) { sb.Append("&"); } sb.AppendFormat("{0}={1}", name, value); first = false; } string content = sb.ToString(); //Trace.WriteLine("content : \"{0}\"", content); HttpRequest httpRequest = new HttpRequest { Url = urlForm, Content = content, Method = Http.GetHttpRequestMethod(method) }; HttpRequestParameters httpRequestParameters = new HttpRequestParameters(); Http http = HttpManager.CurrentHttpManager.Load(httpRequest, httpRequestParameters); //xeSource = new XXElement(http.zGetXmlDocument().Root); //if (!IsLoggedIn(xeSource)) // throw new PBException("unable login to http://www.ebookdz.com/"); return(http); }
public static void Test_Login_01(string url) { XmlConfig localConfig = new XmlConfig(XmlConfig.CurrentConfig.GetExplicit("LocalConfig")); string login = localConfig.GetExplicit("DownloadAutomateManager/Ebookdz/Login"); string hashPassword = Crypt.ComputeMD5Hash(localConfig.GetExplicit("DownloadAutomateManager/Ebookdz/Password")).zToHex(lowercase: true); string urlSite = "http://www.ebookdz.com/"; HttpRequestParameters_v1 requestParameters = new HttpRequestParameters_v1(); pb.old.Http_v2.LoadUrl(urlSite, requestParameters); XXElement xeSource = new XXElement(pb.old.Http_v2.HtmlReader.XDocument.Root); Trace.WriteLine("Login : \"{0}\"", Test_GetLogin_01(xeSource)); Trace.WriteLine("Is logged in : \"{0}\"", Test_IsLoggedIn_01(xeSource)); // <base href="http://www.ebookdz.com/forum/" /> string urlBase = xeSource.XPathValue("//head//base/@href"); //string urlBase = xeSource.XPathValue("//body//base/@href"); Trace.WriteLine("urlBase : \"{0}\"", urlBase); XXElement xeForm = xeSource.XPathElement("//form[@id='navbar_loginform']"); if (xeForm.XElement == null) { Trace.WriteLine("element not found \"//form[@id='navbar_loginform']\""); return; } Trace.WriteLine("form action : \"{0}\"", xeForm.XPathValue("@action")); string urlForm = zurl.GetUrl(urlBase, xeForm.XPathValue("@action")); string method = xeForm.XPathValue("@method"); Trace.WriteLine("urlForm : \"{0}\" method {1}", urlForm, method); StringBuilder sb = new StringBuilder(); bool first = true; foreach (XXElement xeInput in xeForm.XPathElements(".//input")) { string name = xeInput.XPathValue("@name"); if (name == null) { continue; } string value = null; if (name == "vb_login_username") { value = login; } else if (name == "vb_login_password") { value = null; } else if (name == "vb_login_md5password" || name == "vb_login_md5password_utf") { value = hashPassword; } else { value = xeInput.XPathValue("@value"); } if (!first) { sb.Append("&"); } sb.AppendFormat("{0}={1}", name, value); first = false; } string content = sb.ToString(); Trace.WriteLine("content : \"{0}\"", content); requestParameters.content = content; requestParameters.method = Http.GetHttpRequestMethod(method); pb.old.Http_v2.LoadUrl(urlForm, requestParameters); //CookieCollection cookies = requestParameters.cookies.GetCookies(new Uri(urlSite)); //Trace.WriteLine("cookies :"); //Trace.WriteLine(cookies.zToJson()); requestParameters.method = HttpRequestMethod.Get; requestParameters.content = null; pb.old.Http_v2.LoadUrl(url, requestParameters); xeSource = new XXElement(pb.old.Http_v2.HtmlReader.XDocument.Root); Trace.WriteLine("Login : \"{0}\"", Test_GetLogin_01(xeSource)); Trace.WriteLine("Is logged in : \"{0}\"", Test_IsLoggedIn_01(xeSource)); string cookiesFile = Path.Combine(XmlConfig.CurrentConfig.GetExplicit("Ebookdz/CookiesDir"), "cookies.txt"); Trace.WriteLine("save cookies to \"{0}\"", cookiesFile); //zfile.CreateFileDirectory(cookiesFile); //CookieCollection cookies = requestParameters.cookies.GetCookies(new Uri(urlSite)); //cookies.zSave(cookiesFile); zcookies.SaveCookies(requestParameters.cookies, urlSite, cookiesFile); //cookies = requestParameters.cookies.GetCookies(new Uri(urlSite)); //Trace.WriteLine("cookies :"); //Trace.WriteLine(cookies.zToJson()); }