private void button6_Click(object sender, EventArgs e) { #region [Appconfig] string domainName = AppHelper.DomainName; string subDomain = AppHelper.SubDomain; string com_code = AppHelper.Com_code; string idLogin = AppHelper.IdLogin; string password = AppHelper.Password; string selHour = AppHelper.SelHour; string selMin = AppHelper.SelMin; string selAm = AppHelper.SelAm; string hidSelDate = DateTime.Now.ToString("yyyy-MM-dd"); CookieContainer cookieAuthor = new System.Net.CookieContainer(); #endregion #region [Login to Ecount system] // Login Eccount bool resultLogin = LoginSystem(subDomain, com_code, idLogin, password, cookieAuthor); var APILoginDto = new ApiResult(); // Sumit to Clock In if (resultLogin == true) { string AlertAutoLogin = "******"; APILoginDto = AutoClock_In(domainName, subDomain, selHour, selMin, selAm, hidSelDate, cookieAuthor); if (APILoginDto.Html.Contains("EGM014M")) { AlertAutoLogin += string.Format( "Clock in thành công tại {0} : {1} : {2} : {3}", selHour , selMin, selAm, hidSelDate); APILoginDto.Html = AlertAutoLogin; } else { APILoginDto.Html = AlertAutoLogin + "Clock In không thành công"; } this.BoxResult(APILoginDto); } else { APILoginDto.Html = "Login Fail nè"; this.BoxResult(APILoginDto); } #endregion }
private void BoxResult(ApiResult AllOrderDetail) { webBrowser1.ScriptErrorsSuppressed = true; webBrowser1.DocumentText = AllOrderDetail.Html; }
/// <summary> /// 웹서버에 데이터 요청 /// </summary> /// <param name="strUrl">API URL</param> /// <param name="strMethod">POST/GET</param> /// <param name="strPost">POST방식일 경우 값</param> /// <returns></returns> public static ApiResult GetWebRequest(string strUrl, string strMethod, string strPost, Encoding encoding, Dictionary<string, string> dicHeader, CookieContainer cookie, int timeout = 120000, string referer = "", string contentType = null) { ApiResult apiResponse = new ApiResult(); Dictionary<string, string> dicResult = new Dictionary<string, string>(); Uri uri = new Uri(strUrl); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); HttpWebRequest.DefaultWebProxy = new WebProxy("127.0.0.1", 8888); ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; request.Method = strMethod; request.Timeout = timeout; // Header if (dicHeader == null || dicHeader.Count() == 0) { //request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0"; //request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8"; //request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"; request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko"; request.ContentType = "application/x-www-form-urlencoded"; request.Accept = "application/json, text/javascript, */*; q=0.01"; request.Credentials = CredentialCache.DefaultCredentials; if (referer != "") { request.Referer = referer; } } if (contentType != null) { request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8"; } // 추가 헤더 정보 if (dicHeader != null) { foreach (KeyValuePair<string, string> k in dicHeader) { request.Headers.Add(k.Key, k.Value); } } // Cookie request.CookieContainer = cookie; HttpWebResponse response = null; try { if (strMethod == "POST") { // POST 데이터 생성 if (!string.IsNullOrEmpty(strPost)) { byte[] bytePost = encoding.GetBytes(strPost); request.ContentLength = bytePost.Length; Stream dataStream = request.GetRequestStream(); dataStream.Write(bytePost, 0, bytePost.Length); dataStream.Close(); } } // 웹페이지 호출 response = (HttpWebResponse)request.GetResponse(); // 결과 수신 StreamReader reader = new StreamReader(response.GetResponseStream(), encoding); apiResponse.Html = reader.ReadToEnd(); apiResponse.StatusCode = ((System.Net.HttpWebResponse)(response)).StatusCode; apiResponse.headers = response.Headers; apiResponse.cookieContainer = request.CookieContainer; apiResponse.WebRequest = request; } catch (WebException wex) { // 결과 수신(에러) StreamReader reader = new StreamReader(wex.Response.GetResponseStream(), encoding); apiResponse.Html = reader.ReadToEnd(); apiResponse.StatusCode = ((System.Net.HttpWebResponse)(wex.Response)).StatusCode; apiResponse.headers = wex.Response.Headers; } finally { if (response != null) response.Close(); } return apiResponse; }