public CarInfo(string content) { ResponseChecker.CreckForError(content); LicensePlate = content.Substring("Rendszám: <strong>", "</strong>"); Product = content.Substring("Gyártmány: <strong>", "</strong>"); Type = content.Substring("Típus: <strong>", "</strong>"); Color = HttpUtility.HtmlDecode(content.Substring("Szin: <strong>", "</strong>")); Wanted = !content.Substring("A jármű körözés alatt áll? <strong>", "</strong>").Equals("nem", StringComparison.CurrentCultureIgnoreCase); Insurance = HttpUtility.HtmlDecode(content.Substring("A kötelező gépjármű-felelősségbiztosítás adatai: <strong>", "</strong>")); TrafficData = HttpUtility.HtmlDecode(content.Substring("Forgalmi adatok: <strong>", "</strong>")); Other = HttpUtility.HtmlDecode(content.Substring("Egyéb: <strong>", "</strong>")); }
private static async Task <CarInfo> GetCarInfoAsync(string user, string pass, string licensePlate) { if (licensePlate.Length != 7) { throw new Exception("Érvénytelen rendszám-formátum. Helyesen: WWW-123. Egyedi rendszám esetén: WWWW-12 vagy WWWWW-1"); } const string serviceLink = "https://kereses.magyarorszag.hu/gepjarmukereso"; using (var httpClient = new HttpClient { BaseAddress = new Uri("https://gate.gov.hu") }) { httpClient.DefaultRequestHeaders.Add("User-Agent", "Apache-HttpClient/4.1.1 (java 1.5)"); var content = new FormUrlEncodedContent(new KeyValuePair <string, string>[] { new KeyValuePair <string, string>("partnerid", "mohu"), new KeyValuePair <string, string>("felhasznaloNev", user), new KeyValuePair <string, string>("jelszo", pass), new KeyValuePair <string, string>("target", serviceLink), new KeyValuePair <string, string>("artifact", null) }); var result = await httpClient.PostAsync("/sso/ap/ApServlet", content); if (result.StatusCode == HttpStatusCode.OK) { string resultContent = await result.Content.ReadAsStringAsync(); if (resultContent.IndexOf("sikeresen bejelentkezett") > 0) { result = await httpClient.GetAsync($"/sso/InterSiteTransfer?TARGET={serviceLink}/CarSearchWindow?id=frmCarSearch&PARTNER=mohu&struts.portlet.mode=view&dynamicAttributes=%7B%7D&struts.portlet.action=%2FcarSearchPortlet%2FcarSearchPortlet%2FshowCarSearchViewPortlet&templateDir=custom&theme=simple&action=d&windowstate=normal&mode=view"); resultContent = await result.Content.ReadAsStringAsync(); var jsessionid = resultContent.Substring("jsessionid=", "\""); result = await httpClient.GetAsync($"{serviceLink}/CarSearchWindow?jsessionid={jsessionid}&PARTNER=mohu&id=frmCarSearch&struts.portlet.mode=view&dynamicAttributes=%7B%7D&struts.portlet.action=%2FcarSearchPortlet%2FcarSearchPortlet%2FshowCarSearchViewPortlet&templateDir=custom&theme=simple&action=d&windowstate=normal&mode=view&licensePlate={licensePlate}®istrationBook=&pretence=1"); resultContent = await result.Content.ReadAsStringAsync(); return(new CarInfo(resultContent)); } else { ResponseChecker.CreckForError(resultContent); } } return(null); } }