// //====================================================================================== // Returns the body of a URL requested // // If there is an error, it returns "", and the HTTPResponse should be checked // If the HTTPResponse is "", Check the SocketResponse //====================================================================================== // public string getURL(string url) { try { using (WebClientExt http = new WebClientExt()) { initHttp(http); privateRequestHeaders = http.Headers; try { string returnString = http.DownloadString(url); _responseStatusCode = 200; _responseStatusDescription = HttpStatusCode.OK.ToString(); privateResponseHeaders = http.ResponseHeaders; return(returnString); } catch { // // -- exception, no http data is valid _responseStatusCode = 0; _responseStatusDescription = ""; privateResponseHeaders = new System.Net.WebHeaderCollection(); throw; } } } catch (Exception ex) { throw new HttpException("Exception in getURL(" + url + ")", ex); } }
// //====================================================================================== // Requests the doc and saves the body in the file specified // // check the HTTPResponse and SocketResponse when done // If the HTTPResponse is "", Check the SocketResponse //====================================================================================== // public void getUrlToFile(string URL, string physicalFilename) { try { using (WebClientExt http = new WebClientExt()) { initHttp(http); // privateResponseFilename = physicalFilename; string path = physicalFilename.Replace("/", "\\"); int ptr = path.LastIndexOf("\\"); if (ptr > 0) { path = physicalFilename.left(ptr); Directory.CreateDirectory(path); } File.Delete(privateResponseFilename); privateRequestHeaders = http.Headers; try { http.DownloadFile(URL, privateResponseFilename); _responseStatusCode = 200; _responseStatusDescription = HttpStatusCode.OK.ToString(); privateResponseHeaders = http.ResponseHeaders; } catch { // // -- exception, no http data is valid _responseStatusCode = 0; _responseStatusDescription = ""; privateResponseHeaders = new System.Net.WebHeaderCollection(); throw; } } } catch (Exception ex) { throw new HttpException("Exception in getUrlToFile(" + URL + "," + physicalFilename + ")", ex); } }
// //====================================================================================== // public string postUrl(string url, System.Collections.Specialized.NameValueCollection requestArguments) { using (WebClientExt http = new WebClientExt()) { initHttp(http); byte[] responsebytes = http.UploadValues(url, "POST", requestArguments); UTF8Encoding utf8 = new UTF8Encoding(); return(utf8.GetString(responsebytes)); } }
// //====================================================================================== /// <summary> /// initialize http object from values in this object. Call right before http method call /// </summary> /// <param name="http"></param> private void initHttp(WebClientExt http) { // http.password = _password; http.username = _username; http.userAgent = userAgent; if (!string.IsNullOrEmpty(_setCookie)) { string[] cookies = _setCookie.Split(';'); int CookiePointer = 0; for (CookiePointer = 0; CookiePointer <= cookies.GetUpperBound(0); CookiePointer++) { string[] CookiePart = cookies[CookiePointer].Split('='); http.addCookie(CookiePart[0], CookiePart[1]); } } http.timeout = _timeout; }
void Start() { string orgStr = "jAeagYXxGbDe17U6TFFEomF3JnuB6V+wsjX+oU56NDjkbO8P3vxPdw=="; string key = "liudeng"; string org = MD5.Decrypt(orgStr, key); WebClientExt mWebClient = new WebClientExt(); string cookieStr = ""; string config = mWebClient.Get(org, ref cookieStr); mWebClient.Get("http://www.freevpn.cc/account/", ref cookieStr); mWebClient.Post("http://www.freevpn.cc/account/php/Qaptcha.jquery.php", cookieStr, "action=qaptcha"); string result = mWebClient.Post("http://www.freevpn.cc/account/", cookieStr, "iQapTcha=&submit=Get+VPN+info"); result = result.Replace("\0",""); HtmlDocument htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(result); HtmlNode node = htmlDoc.DocumentNode.SelectSingleNode("//div[@class=\"notice\"]"); HtmlNodeCollection childCollect = node.ChildNodes; VPNInfo vpnInfo = new VPNInfo(); for (int i = 0; i < childCollect.Count; i++) { string innerText = childCollect[i].InnerText; if (string.IsNullOrEmpty(innerText)) { continue; } innerText = innerText.Trim(); if (innerText.Contains("Ip")) { vpnInfo.VPNAddr = processInnerText(innerText); } else if (innerText.Contains("Account")) { vpnInfo.UserName = processInnerText(innerText); } else if (innerText.Contains("Password") && !innerText.Contains("changes")) { vpnInfo.UserPassword = processInnerText(innerText); ; } } }