private void GetPassKey(SchAirlineQueryJsonModel model) { WebClient client = InitClient(); //http://www.scal.com.cn/Web/Reservation?type=single var result = client.DownloadString("http://www.scal.com.cn/Web/Base/isVali"); client = InitClient(); String para = "AirlineParamJSON=" + "{\"AirlineType\":\"Single\",\"IsFixedCabin\":false,\"RouteList\":[{\"RouteIndex\":1,\"RouteName\":\"单 程\",\"OrgCity\":\"CKG\",\"DesCity\":\"PVG\",\"OrgCityName\":\"重庆\",\"DesCityName\":\"上海浦东\",\"FlightDate\":\"2015-12-14\"}],\"AVType\":0}"; String parajson = "AirlineParamJSON" + JsonConvert.SerializeObject(model); _log.Debug(para); _log.Debug(parajson); client.Headers.Add(HttpRequestHeader.Referer, "http://www.scal.com.cn/Web"); var rdata = client.UploadData("http://www.scal.com.cn/Web/ETicket/AirlineList", "POST", Encoding.UTF8.GetBytes(para)); String resultheml = Encoding.GetEncoding("utf-8").GetString(rdata); Int32 i = resultheml.IndexOf("PassKey", 0) + "PassKey".Length + 3; Int32 j = resultheml.IndexOf("}", i) - 1; String pk = resultheml.Substring(i, j - i); _passkey = pk; _log.Debug(String.Format("PassKey::{0}",pk)); }
public List<String> QuerySingle(Uri queryUri,SchAirlineQueryJsonModel model) { if (String.IsNullOrEmpty(_passkey)) { GetPassKey(model); } model.PassKey = _passkey; List<String> lists = new List<string>(); WebClient client = InitClient(); client.Headers.Add(HttpRequestHeader.Referer, "http://www.scal.com.cn/Web/ETicket/AirlineList"); Validation(); _log.Debug(model.ToString()); client = InitClient(); client.Headers.Add(HttpRequestHeader.Referer, "http://www.scal.com.cn/Web/ETicket/AirlineList"); var rdata = client.UploadData(queryUri, "POST", Encoding.UTF8.GetBytes(model.ToString())); String resultheml = Encoding.UTF8.GetString(rdata); try { if (resultheml.Contains("系统繁忙")) { return QuerySingle(queryUri, model); } else if (resultheml.Contains("查询当日无航班")) { if (_cnt < 3) { return QuerySingle(queryUri, model); _cnt++; } else { _cnt = 0; return lists; } } else { _jsonModel = JsonConvert.DeserializeObject<SchAilrLineJsonModel>(resultheml); _jsonModel.AirlineListJSONModel = JsonConvert.DeserializeObject<AirlineListJSONModel>(_jsonModel.AirlineListJSON); JObject jobj=(JObject) JsonConvert.DeserializeObject(resultheml); } } catch (Exception ex) { _log.Debug("AirLineInformationModel to model", ex); } //_log.Debug(resultheml); return lists; }