private LoginResponse Login() { GetVerificationToken(); var bodyObject = new LogonBody { KodMishtamesh = GetCodeMishtamesh(), MisparZihuy = _idNumber, Sisma = _password }; var body = JsonConvert.SerializeObject(bodyObject); var encoding = new ASCIIEncoding(); byte[] bytes = encoding.GetBytes(body); WebRequest request = WebRequest.Create(@"https://he.americanexpress.co.il/services/ProxyRequestHandler.ashx?reqName=performLogonA"); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = bytes.Length; request.Headers.Add(RequestVerificationToken, _sessionInfo.RequestVerificationTokenInput); request.TryAddCookie(new Cookie(RequestVerificationToken, _sessionInfo.RequestVerificationToken) { Domain = LoginDomain }); string response = SendRequest(request, bytes); var result = JsonConvert.DeserializeObject <LoginResponse>(response); return(result); }
private LoginResponse Login(string idNumber, string lastDigits, string password) { var api = "/services/ProxyRequestHandler.ashx?reqName=performLogonA"; var baseAddress = new Uri(LoginDomain); var body = new LogonBody { MisparZihuy = idNumber, CountryCode = "212", IdType = "1", Sisma = password, CardSuffix = lastDigits }; var headersToAdd = new List <KeyValuePair <string, IEnumerable <string> > > { new KeyValuePair <string, IEnumerable <string> > (RequestVerificationToken, new List <string> { _sessionInfo.AntiForgeryToken }), }; var cookieContainer = new CookieContainer(); cookieContainer.Add(baseAddress, new Cookie(RequestVerificationToken, _sessionInfo.RequestVerificationToken)); cookieContainer.Add(baseAddress, new Cookie(Alt50_ZLinuxPrd, _sessionInfo.Alt50_ZLinuxPrd)); cookieContainer.Add(baseAddress, new Cookie(Jsessionid, _sessionInfo.Jsessionid)); cookieContainer.Add(baseAddress, new Cookie(ServiceP, _sessionInfo.ServiceP)); cookieContainer.Add(baseAddress, new Cookie(AspDotNetSessionId, _sessionInfo.AspDotNetSessionId)); var content = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/x-www-form-urlencoded"); var response = CallPostRequest <LoginResponse>(baseAddress, api, content, cookieContainer, headersToAdd); if (response.Status != 1) { throw new UnauthorizedAccessException(String.Concat(response.Message, "\n Go to: \n", LoginDomain, "/personalarea/login/")); } return(response); }