public static async System.Threading.Tasks.Task <string> getResponseAsString(string requestUri)
        {
            using (var client = new HttpClient())
            {
                //var cookieId = ExtranetUsersRepository.AuthCookie;
                //System.Diagnostics.Debug.WriteLine("\n\nSession ID: \t" + cookieId["ASP.NET_SessionId"] + "\nAuthorization Token: \t" + cookieId[".auth"] + "\n\n");

                client.BaseAddress = new Uri("https://extranet.newtonideas.com");
                client.DefaultRequestHeaders.Accept.Clear();

                //Setting Cookie
                string cookie = "XCMWSERV = default; require_ssl=true; language_code=en-US;";
                ExtranetUsersRepository.AddAuthorizationInfo(ref cookie);
                client.DefaultRequestHeaders.Add("Cookie", cookie);
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                //Getting Response
                var response = await client.GetAsync(requestUri);

                response.EnsureSuccessStatusCode();
                var stringResult = await response.Content.ReadAsStringAsync();

                return(stringResult);
            }
        }
Ejemplo n.º 2
0
        public IEnumerable <Timelog> GetAll()
        {
            using (var client = new HttpClient()) {
                List <Timelog> timelogs = new List <Timelog>();

                //Retrieving a JSON-Object
                var response = ExtranetUsersRepository.getResponseAsString("/api/ApiAlpha.ashx/w/TTI/a/TIMELOG/tickets/list?&listOfFields=ALL&withTechnicalData=true").Result;

                var json    = JObject.Parse(response);
                var results = json["data"].Children().ToList();

                //Serialization
                foreach (JToken t in results)
                {
                    Timelog timelog = t.ToObject <Timelog>();
                    timelogs.Add(timelog);
                }

                return(timelogs);
            }
        }