예제 #1
0
        static async Task MyAPIPut(HttpClient cons)
        {
            using (cons)
            {
                HttpResponseMessage res = await cons.GetAsync("api/tblTags/4");

                res.EnsureSuccessStatusCode();
                if (res.IsSuccessStatusCode)
                {
                    tblTag tag = await res.Content.ReadAsAsync <tblTag>();

                    tag.tagName = "New Tag";
                    res         = await cons.PutAsJsonAsync("api/tblTags/4", tag);

                    Console.WriteLine("\n");
                    Console.WriteLine("\n");
                    Console.WriteLine("-----------------------------------------------------------");
                    Console.WriteLine("------------------Calling Put Operation--------------------");
                    Console.WriteLine("\n");
                    Console.WriteLine("\n");
                    Console.WriteLine("-----------------------------------------------------------");
                    Console.WriteLine("tagId    tagName          tagDescription");
                    Console.WriteLine("-----------------------------------------------------------");
                    Console.WriteLine("{0}\t{1}\t\t{2}", tag.tagId, tag.tagName, tag.tagDescription);
                    Console.WriteLine("\n");
                    Console.WriteLine("\n");
                    Console.WriteLine("-----------------------------------------------------------");

                    Console.ReadLine();
                }
            }
        }
예제 #2
0
        static async Task MyAPIPost(HttpClient cons)
        {
            using (cons)
            {
                var tag = new tblTag {
                    tagName = "Web API", tagDescription = "This tag is all about Web API"
                };
                HttpResponseMessage res = await cons.PostAsJsonAsync("api/tblTags", tag);

                res.EnsureSuccessStatusCode();
                if (res.IsSuccessStatusCode)
                {
                    Console.WriteLine("\n");
                    Console.WriteLine("\n");
                    Console.WriteLine("-----------------------------------------------------------");
                    Console.WriteLine("------------------Calling Post Operation--------------------");
                    Console.WriteLine("------------------Created Successfully--------------------");
                    Console.ReadLine();
                }
            }
        }