当前位置: 首页>>代码示例>>C#>>正文


C# HttpClient.PutAsXmlAsync方法代码示例

本文整理汇总了C#中System.Net.Http.HttpClient.PutAsXmlAsync方法的典型用法代码示例。如果您正苦于以下问题:C# HttpClient.PutAsXmlAsync方法的具体用法?C# HttpClient.PutAsXmlAsync怎么用?C# HttpClient.PutAsXmlAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.Http.HttpClient的用法示例。


在下文中一共展示了HttpClient.PutAsXmlAsync方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Put_throws_not_implemented_exception

        public void Put_throws_not_implemented_exception()
        {
            var config = new HttpSelfHostConfiguration("http://localhost:8080");

            config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Never;
            config.Filters.Add(new NotImplementedErrorFilter());
            config.Routes.MapHttpRoute(
                "DefaultApi", "api/{controller}/{id}",
                new { id = RouteParameter.Optional });
            config.Formatters.Add(new EuricomFormatter());
            config.MessageHandlers.Add(new MethodOverrideHandler());
            config.DependencyResolver = new DependencyResolver();

            var server = new HttpServer(config);
            var client = new HttpClient(server);

            var result = client.PutAsXmlAsync<Bank>("http://localhost:8080/api/bank/1", (new Bank() { BIC = "1", Name = "KBC" })).Result;

            Assert.AreEqual(HttpStatusCode.NotImplemented, result.StatusCode);
        }
开发者ID:JefClaes,项目名称:aspnet-webapi-samples-tunisia,代码行数:20,代码来源:BankControllerIntegrationTest.cs

示例2: PutUpdateOrder

 /// <summary>
 /// Calls API to update order.
 /// </summary>
 /// <param name="updatedOrder">Updated order to be saved</param>
 /// <param name="editEvents">List of id's of edit events to be executed</param>
 /// <returns>Tuple of bool and string, bool == true when API succeded, bool == false when API did not succeed, string == fail message.</returns>
 public Tuple<bool, string> PutUpdateOrder(Order updatedOrder, List<int> editEvents)
 {
     using (var client = new HttpClient())
     {
         try
         {
             var dto = new Tuple<Order, List<int>>(updatedOrder, editEvents);
             client.BaseAddress = _baseAddress;
             var response = client.PutAsXmlAsync("api/order/updateorder", dto).Result;
             if (response.IsSuccessStatusCode)
             {
                 return new Tuple<bool, string>(true, response.StatusCode.ToString());
             }
             else //do failure thing
             {
                 return new Tuple<bool, string>(false, "Could not save updated order: Error from Web api: " + response.StatusCode.ToString() + ": " + response.ReasonPhrase);
             }
         }
         catch (Exception ex)
         {
             throw;
         }
     }
 }
开发者ID:PeterOeClausen,项目名称:Bachelorproject,代码行数:30,代码来源:APICaller.cs

示例3: UpdateSongAsXML

 internal static void UpdateSongAsXML(HttpClient Client, int id, Song song)
 {
     var response = Client.PutAsXmlAsync("api/Songs/" + id, song).Result;
     if (response.IsSuccessStatusCode)
     {
         Console.WriteLine("Song updated!");
     }
     else
     {
         Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
     }
 }
开发者ID:sabrie,项目名称:TelerikAcademy,代码行数:12,代码来源:SongsCRUD.cs

示例4: UpdateAlbumAsXML

 internal static void UpdateAlbumAsXML(HttpClient Client, int id, Album album)
 {
     var response = Client.PutAsXmlAsync("api/Albums/" + id, album).Result;
     if (response.IsSuccessStatusCode)
     {
         Console.WriteLine("Album updated!");
     }
     else
     {
         Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
     }
 }
开发者ID:sabrie,项目名称:TelerikAcademy,代码行数:12,代码来源:AlbumsCRUD.cs

示例5: PutArtistXml

        public static void PutArtistXml(HttpClient client)
        {
            client.DefaultRequestHeaders.Accept.Add(new
                MediaTypeWithQualityHeaderValue("application/xml"));

            Console.WriteLine("Enter artist id");
            string id = Console.ReadLine();

            Console.WriteLine("Enter artist name");
            string name = Console.ReadLine();
            Console.WriteLine("Enter artist country");
            string country = Console.ReadLine();
            Console.WriteLine("Enter artist birth date");
            DateTime birthDate = DateTime.ParseExact(Console.ReadLine(), "dd.MM.yyyy", new CultureInfo("en-US"));
            Artist artist = new Artist { Name = name, Country = country, DateOfBirth = birthDate };
            HttpResponseMessage response =
                client.PutAsXmlAsync(string.Format("api/artists/{0}", id), artist).Result;

            if (response.IsSuccessStatusCode)
            {
                Console.WriteLine("Artist changed");
            }
            else
            {
                Console.WriteLine("{0} ({1})",
                    (int)response.StatusCode, response.ReasonPhrase);
            }
        }
开发者ID:vasilkrvasilev,项目名称:WebServices,代码行数:28,代码来源:ArtistCommand.cs

示例6: PutSongXml

        public static void PutSongXml(HttpClient client)
        {
            client.DefaultRequestHeaders.Accept.Add(new
                MediaTypeWithQualityHeaderValue("application/xml"));

            Console.WriteLine("Enter song id");
            string songId = Console.ReadLine();

            Console.WriteLine("Enter song title");
            string title = Console.ReadLine();
            Console.WriteLine("Enter song year");
            int year = int.Parse(Console.ReadLine());
            Console.WriteLine("Enter song genre code");
            Genre genre = (Genre)int.Parse(Console.ReadLine());
            Console.WriteLine("Enter song description");
            string description = Console.ReadLine();
            Console.WriteLine("Enter song artist id");
            int id = int.Parse(Console.ReadLine());
            Song song = new Song { SongTitle = title, SongYear = year, SongGenre = genre, Description = description, ArtistId = id };
            HttpResponseMessage response =
                client.PutAsXmlAsync(string.Format("api/songs/{0}", songId), song).Result;

            if (response.IsSuccessStatusCode)
            {
                Console.WriteLine("Song changed");
            }
            else
            {
                Console.WriteLine("{0} ({1})",
                    (int)response.StatusCode, response.ReasonPhrase);
            }
        }
开发者ID:vasilkrvasilev,项目名称:WebServices,代码行数:32,代码来源:SongCommand.cs

示例7: UpdateSong

        public static void UpdateSong(HttpClient client, int id, Artist song)
        {
            HttpResponseMessage response;
            if (client.DefaultRequestHeaders.Accept.Contains(new MediaTypeWithQualityHeaderValue("application/json")))
            {
                response = client.PutAsJsonAsync("api/songs/" + id, song).Result;
            }
            else
            {
                response = client.PutAsXmlAsync("api/songs/" + id, song).Result;
            }

            if (response.IsSuccessStatusCode)
            {
                Console.WriteLine("Song {0} updated successfully", song.Name);
            }
            else
            {
                Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
            }
        }
开发者ID:vanndann,项目名称:TelerikAcademy,代码行数:21,代码来源:MusicCatalogDAL.cs

示例8: PutAlbumXml

        public static void PutAlbumXml(HttpClient client)
        {
            client.DefaultRequestHeaders.Accept.Add(new
                MediaTypeWithQualityHeaderValue("application/xml"));

            Console.WriteLine("Enter album id");
            string albumId = Console.ReadLine();

            Console.WriteLine("Enter album title");
            string title = Console.ReadLine();
            Console.WriteLine("Enter album year");
            int year = int.Parse(Console.ReadLine());
            Console.WriteLine("Enter producer");
            string producer = Console.ReadLine();
            Album album = new Album { AlbumTitle = title, AlbumYear = year, Producer = producer };
            HttpResponseMessage response =
                client.PutAsXmlAsync(string.Format("api/songs/{0}", albumId), album).Result;

            if (response.IsSuccessStatusCode)
            {
                Console.WriteLine("Album changed");
            }
            else
            {
                Console.WriteLine("{0} ({1})",
                    (int)response.StatusCode, response.ReasonPhrase);
            }
        }
开发者ID:vasilkrvasilev,项目名称:WebServices,代码行数:28,代码来源:AlbumCommand.cs

示例9: PutExecuteEvent

 /// <summary>
 /// Execute event on API
 /// </summary>
 /// <param name="eventToExecute">Event to execute</param>
 /// <returns>Tuple of bool and string, bool == true when API succeded, bool == false when API did not succeed, string == fail message.</returns>
 public Tuple<bool, string> PutExecuteEvent(Event eventToExecute)
 {
     using (var client = new HttpClient())
     {
         client.BaseAddress = _baseAddress;
         var response = client.PutAsXmlAsync("api/order/executeevent", eventToExecute).Result;
         if (response.IsSuccessStatusCode)
         {
             return new Tuple<bool, string>(true, response.StatusCode.ToString());
         }
         else //do failure thing
         {
             return new Tuple<bool, string>(false, "Could not execute event: Error from Web api: " + response.StatusCode.ToString() + ": " + response.ReasonPhrase);
         }
     }
 }
开发者ID:PeterOeClausen,项目名称:Bachelorproject,代码行数:21,代码来源:APICaller.cs

示例10: PutDeleteOrder

 /// <summary>
 /// Archives order on Web API (Does not delete order on Web API)
 /// </summary>
 /// <param name="order">Order to be deleted</param>
 /// <returns>Tuple of bool and string. bool == true when API succeded, bool == false when API did not succeed, string == fail message.</returns>
 public Tuple<bool, string> PutDeleteOrder(Order order)
 {
     using (var client = new HttpClient())
     {
         try
         {
             client.BaseAddress = _baseAddress;
             var response = client.PutAsXmlAsync("api/order/archive", order).Result; //Archiving, not deleting
             if (response.IsSuccessStatusCode)
             {
                 return new Tuple<bool, string>(true, response.StatusCode.ToString());
             }
             else //do failure thing
             {
                 return new Tuple<bool, string>(false, "Could not delete order: Error from Web api: " + response.StatusCode.ToString() + ": " + response.ReasonPhrase);
             }
         }
         catch (Exception ex)
         {
             throw;
         }
     }
 }
开发者ID:PeterOeClausen,项目名称:Bachelorproject,代码行数:28,代码来源:APICaller.cs

示例11: UpdateAlbum

        public static void UpdateAlbum(HttpClient client, int id, string newTitle = null,
            string newProducer = null, int? newYear = null)
        {
            if (id <= 0)
            {
                throw new ArgumentOutOfRangeException("Id must be a positive integer.");
            }

            HttpResponseMessage response = client.GetAsync("api/Album/" + id).Result;
            if (response.IsSuccessStatusCode)
            {
                var album = response.Content.ReadAsAsync<SerializableAlbum>().Result;

                Album updatedAlbum = new Album();
                updatedAlbum.AlbumId = id;

                if (newTitle != null)
                {
                    updatedAlbum.Title = newTitle;
                }
                else
                {
                    updatedAlbum.Title = album.Title;
                }

                if (newProducer != null)
                {
                    updatedAlbum.Producer = newProducer;
                }
                else
                {
                    updatedAlbum.Producer = album.Producer;
                }

                if (newYear != null)
                {
                    updatedAlbum.Year = newYear.Value;
                }
                else
                {
                    updatedAlbum.Year = album.Year;
                }

                HttpResponseMessage innerResponse = null;

                if (client.DefaultRequestHeaders.Accept.Contains(new MediaTypeWithQualityHeaderValue("application/xml")))
                {
                    innerResponse = client.PutAsXmlAsync<Album>("api/Album/" + id, updatedAlbum).Result;
                }
                else if (client.DefaultRequestHeaders.Accept.Contains(new MediaTypeWithQualityHeaderValue("application/json")))
                {
                    innerResponse = client.PutAsJsonAsync<Album>("api/Album/" + id, updatedAlbum).Result;
                }

                if (innerResponse == null)
                {
                    throw new InvalidOperationException("Client must use json or xml.");
                }

                if (innerResponse.IsSuccessStatusCode)
                {
                    Console.WriteLine("Update successful.");
                }
                else
                {
                    Console.WriteLine("{0} ({1})", (int)innerResponse.StatusCode, innerResponse.ReasonPhrase);
                }
            }
            else
            {
                Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
            }
        }
开发者ID:PetarPenev,项目名称:Telerik,代码行数:73,代码来源:PutOperations.cs

示例12: UpdateArtist

        public static void UpdateArtist(HttpClient client, int id, string newName = null, 
            string newCountry = null, DateTime? newDateOfBirth = null)
        {
            if (id <= 0)
            {
                throw new ArgumentOutOfRangeException("Id must be a positive integer.");
            }

            HttpResponseMessage response = client.GetAsync("api/Artist/" + id).Result;
            if (response.IsSuccessStatusCode)
            {
                var artist = response.Content.ReadAsAsync<SerializableArtist>().Result;

                Artist updatedArtist = new Artist();
                updatedArtist.ArtistId = id;

                if (newCountry != null)
                {
                    updatedArtist.Country = newCountry;
                }
                else
                {
                    updatedArtist.Country = artist.Country;
                }

                if (newDateOfBirth != null)
                {
                    updatedArtist.DateOfBirth = newDateOfBirth.Value;
                }
                else
                {
                    updatedArtist.DateOfBirth = artist.DateOfBirth;
                }

                if (newName != null)
                {
                    updatedArtist.Name = newName;
                }
                else
                {
                    updatedArtist.Name = artist.Name;
                }

                HttpResponseMessage innerResponse = null;

                if (client.DefaultRequestHeaders.Accept.Contains(new MediaTypeWithQualityHeaderValue("application/xml")))
                {
                    innerResponse = client.PutAsXmlAsync<Artist>("api/Artist/" + id, updatedArtist).Result;
                }
                else if (client.DefaultRequestHeaders.Accept.Contains(new MediaTypeWithQualityHeaderValue("application/json")))
                {
                    innerResponse = client.PutAsJsonAsync<Artist>("api/Artist/" + id, updatedArtist).Result;
                }

                if (innerResponse == null)
                {
                    throw new InvalidOperationException("Client must use json or xml.");
                }

                if (innerResponse.IsSuccessStatusCode)
                {
                    Console.WriteLine("Update successful.");
                }
                else
                {
                    Console.WriteLine("{0} ({1})", (int)innerResponse.StatusCode, innerResponse.ReasonPhrase);
                }
            }
            else
            {
                Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
            }
        }
开发者ID:PetarPenev,项目名称:Telerik,代码行数:73,代码来源:PutOperations.cs


注:本文中的System.Net.Http.HttpClient.PutAsXmlAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。