public NewsResultsCache QueryINews() { string uri = WEB_SERVICE_URL; // string.Format(WEB_SERVICE_URL, searchText); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); request.Method = "GET"; request.Headers.Add("Authorization", "7e8f60e325cd06e164799af1e317d7a7"); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream responseStream = response.GetResponseStream(); string jsonString = null; using (StreamReader reader = new StreamReader(responseStream)) { jsonString = reader.ReadToEnd(); reader.Close(); } JObject jResult = JObject.Parse(jsonString); List <JToken> jResults = jResult["dataset"].Children().ToList(); //dataset is object from json List <NewsResult> result = new List <NewsResult>(); foreach (JToken jNewsResult in jResults) { NewsResult newsResult = JsonConvert.DeserializeObject <NewsResult>(jNewsResult.ToString()); result.Add(newsResult); } return(new NewsResultsCache(result)); }
public NewsResultsCache Login(string emailId, string loginCode, string password) { string uri = @"http://alednb:82/ayoooapi/v1/userlogin"; // string.Format(WEB_SERVICE_URL, searchText); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); request.ContentType = "application/x-www-form-urlencoded"; request.Method = "POST"; request.Headers.Add("Authorization", "7e8f60e325cd06e164799af1e317d7a7"); //request.AllowWriteStreamBuffering = true; //using (var streamWriter = new StreamWriter(request.GetRequestStream())) //{ // string json = "{\"emailId\":\""+emailId+"\"," + // "\"loginCode\":\""+loginCode+"\"," + // "\"password\":\""+password+"\"}"; // streamWriter.Write(json); // streamWriter.Flush(); // streamWriter.Close(); //} string paramz = "emailId=" + emailId + "&loginCode=" + loginCode + "&password="******"dataset"].Children().ToList(); //dataset is object from json List <NewsResult> result = new List <NewsResult>(); foreach (JToken jNewsResult in jResults) { NewsResult newsResult = JsonConvert.DeserializeObject <NewsResult>(jNewsResult.ToString()); result.Add(newsResult); } return(new NewsResultsCache(result)); }