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


C# HttpClient.PostAsXmlAsync方法代码示例

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


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

示例1: PostOrderAsync

 /// <summary>
 /// Save order on web api.
 /// </summary>
 /// <param name="newOrder">New Order to be saved.</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> PostOrderAsync(NewOrderInfo newOrder)
 {
     using (var client = new HttpClient())
     {
         try
         {
             client.BaseAddress = _baseAddress;
             var response = client.PostAsXmlAsync("api/order/create", newOrder, new CancellationToken()).Result;
             if (response.IsSuccessStatusCode)
             {
                 var answer = new Tuple<bool, string>(true, response.StatusCode.ToString());
                 return answer;
             }
             else //do failure thing
             {
                 var answer = new Tuple<bool, string>(false, "Could not save the created order: Error from Web api: " + response.StatusCode.ToString() + ": " + response.ReasonPhrase);
                 return answer;
             }
         }
         catch (Exception ex)
         {
             throw;
         }
     }
 }
开发者ID:PeterOeClausen,项目名称:Bachelorproject,代码行数:30,代码来源:APICaller.cs

示例2: ProcessPostRequests

        internal static async void ProcessPostRequests(HttpClient client)
        {
            ResponseAlbumModel album = new ResponseAlbumModel
            {
                Title = "Xml added",
                ProducerName = "Xml Produer",
                Year = 2000
            };

            var httpResponse = await client.PostAsXmlAsync("api/albums", album);
            Console.WriteLine(httpResponse.ReasonPhrase.ToString() + " from albums");
        }
开发者ID:viktorD1m1trov,项目名称:T-Academy,代码行数:12,代码来源:XmlRequests.cs

示例3: AddSongXml

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

            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.PostAsXmlAsync("api/songs", song).Result;

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

示例4: AddArtistXml

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

            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.PostAsXmlAsync("api/artists", artist).Result;

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

示例5: AddAlbumXml

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

            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.PostAsXmlAsync("api/albums", album).Result;

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

示例6: PostCanRespondInXml

        public async void PostCanRespondInXml()
        {
            var message = new MessageDto
            {
                Text = "This is XML"
            };
            var client = new HttpClient(_server);
            var response = await client.PostAsXmlAsync(Url + "hello", message);

            var result = await response.Content.ReadAsAsync<MessageDto>(new [] {new XmlMediaTypeFormatter() });
            
            Assert.Equal(message.Text, result.Text);
        }
开发者ID:diouf,项目名称:apress-recipes-webapi,代码行数:13,代码来源:IntegrationTest.cs

示例7: NotifySites

		public static async Task NotifySites()
		{
			BlogConfigurationDto configuration = configurationDataService.GetConfiguration();
			IEnumerable<Uri> pingSites = pingDataService.GetPingSites();

			foreach (Uri pingSite in pingSites)
			{
				using (HttpClient client = new HttpClient())
				{
					await client.PostAsXmlAsync(pingSite.ToString(), GetRequest(pingSite, configuration));
				}
			}
		}
开发者ID:prabhakara,项目名称:Dexter-Blog-Engine,代码行数:13,代码来源:PingHelper.cs

示例8: AddNewSongAsXML

        internal static Song AddNewSongAsXML(HttpClient Client, string title, int year, string genre, Artist artist)
        {
            var album = new Song() { Title = title, Year = year, Genre = genre, Artist = artist };

            var response = Client.PostAsXmlAsync("api/Songs", album).Result;

            Song resultSong = response.Content.ReadAsAsync<Song>().Result;

            if (response.IsSuccessStatusCode)
            {
                Console.WriteLine("Song added!");
                return resultSong;
            }
            else
            {
                Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
            }

            return new Song();
        }
开发者ID:sabrie,项目名称:TelerikAcademy,代码行数:20,代码来源:SongsCRUD.cs

示例9: AddNewArtistAsXml

        internal static Artist AddNewArtistAsXml(HttpClient Client, string name, string country, DateTime dateOfBirth)
        {
            var artist = new Artist { Name = name, Country = country, DateOfBirth = dateOfBirth };

            var response = Client.PostAsXmlAsync("api/Artists", artist).Result;

            Artist resultArtist = response.Content.ReadAsAsync<Artist>().Result;

            if (response.IsSuccessStatusCode)
            {
                Console.WriteLine("Artist added!");
                return resultArtist;
            }
            else
            {
                Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
            }

            return new Artist();
        }
开发者ID:sabrie,项目名称:TelerikAcademy,代码行数:20,代码来源:ArtistCRUD.cs

示例10: AddNewAlbumAsXml

        internal static Album AddNewAlbumAsXml(HttpClient Client, string title, int year, string producer, ICollection<Song> songs, ICollection<Artist> artists)
        {
            var album = new Album() { Title = title, Year = year, Producer = producer, Songs = songs, Artists = artists };

            var response = Client.PostAsXmlAsync("api/Albums", album).Result;

            Album resultAlbum = response.Content.ReadAsAsync<Album>().Result;

            if (response.IsSuccessStatusCode)
            {
                Console.WriteLine("Album added!");
                return resultAlbum;
            }
            else
            {
                Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
            }

            return new Album();
        }
开发者ID:sabrie,项目名称:TelerikAcademy,代码行数:20,代码来源:AlbumsCRUD.cs

示例11: AddSong

        public static void AddSong(HttpClient client, Song song)
        {
            HttpResponseMessage response;
            if (client.DefaultRequestHeaders.Accept.Contains(new MediaTypeWithQualityHeaderValue("application/json")))
            {
                response = client.PostAsJsonAsync("api/songs", song).Result;
            }
            else
            {
                response = client.PostAsXmlAsync("api/songs", song).Result;
            }

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

示例12: Notify

		public static async Task Notify(ItemDto item, Uri uri)
		{
			SiteUrl itemUrl = item is PostDto
				                  ? urlBuilder.Post.Permalink(item)
				                  : urlBuilder.Page.Permalink(item);

			using (HttpClient client = new HttpClient())
			{
				HttpResponseMessage response = await client.GetAsync(uri);

				KeyValuePair<string, IEnumerable<string>> header = response.Headers.SingleOrDefault(h => h.Key.Equals("x-pingback", StringComparison.OrdinalIgnoreCase) || h.Key.Equals("pingback", StringComparison.OrdinalIgnoreCase));

				string urlToPing = header.Value.FirstOrDefault();

				if (string.IsNullOrEmpty(urlToPing))
				{
					return;
				}

				var xmlRequest = GetXmlRequest(itemUrl, uri);

				await client.PostAsXmlAsync(urlToPing, xmlRequest);
			}
		}
开发者ID:prabhakara,项目名称:Dexter-Blog-Engine,代码行数:24,代码来源:PingbackHelper.cs

示例13: Add

 public static async void Add(HttpClient httpClient, SongApiModel song)
 {
     var response = await httpClient.PostAsXmlAsync("song", song);
     Console.WriteLine("Done!");
 }
开发者ID:atanas-georgiev,项目名称:Web-Services-and-Cloud-Homeworks,代码行数:5,代码来源:Song.cs

示例14: Main

        static void Main(string[] args)
        {
            // Prepare for a simple HttpPost request
            var client = new HttpClient();
            client.BaseAddress = new Uri("http://localhost:61924/");

            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));

            // Get the body of the request
            var vMRRequest = GetSampleRequest();

            // Construct the DSS-level request, base-64 encoding the vMR request within it.
            var evaluate = 
                new evaluate 
                { 
                    interactionId =
                        new InteractionIdentifier 
                        { 
                            interactionId = Guid.NewGuid().ToString("N"), 
                            scopingEntityId = "SAMPLE-CLIENT", 
                            submissionTime = DateTime.Now.ToUniversalTime() 
                        },
                    evaluationRequest =
                        new EvaluationRequest
                        {
                            clientLanguage = "XXX",
                            clientTimeZoneOffset = "XXX",
                            dataRequirementItemData = new List<DataRequirementItemData> 
                            { 
                                new DataRequirementItemData
                                {
                                    driId = new ItemIdentifier { itemId = "RequiredDataId" },
                                    data = 
                                        new SemanticPayload 
                                        { 
                                            informationModelSSId = SemanticSignifiers.CDSInputId, 
                                            base64EncodedPayload = Packager.EncodeRequestPayload(vMRRequest) 
                                        }
                                }
                            },
                            kmEvaluationRequest = new List<KMEvaluationRequest> 
                            { 
                                new KMEvaluationRequest { kmId = new EntityIdentifier { scopingEntityId = "org.hl7.cds", businessId = "NQF-0068", version = "1.0" } }
                            }
                        }
                };

            // Post the request and retrieve the response
            var response = client.PostAsXmlAsync("api/evaluation", evaluate).Result;

            if (response.IsSuccessStatusCode)
            {
                Console.WriteLine("Evaluation succeeded.");
                var evaluateResponse = response.Content.ReadAsAsync<evaluateResponse>().Result;

                var evaluationResponse = evaluateResponse.evaluationResponse.finalKMEvaluationResponse.First();

                if (evaluationResponse.kmId.scopingEntityId != "SAMPLE-CLIENT")
                {
                    Console.WriteLine("Evaluation did not return the input scoping entity Id.");
                }

                var evaluationResult = evaluationResponse.kmEvaluationResultData.First();

                if (!SemanticSignifiers.AreEqual(evaluationResult.data.informationModelSSId, SemanticSignifiers.CDSActionGroupResponseId))
                {
                    Console.WriteLine("Evaluation did not return an action group response.");
                }

                var actionGroupResponse = Packager.DecodeActionGroupResponsePayload(evaluationResult.data.base64EncodedPayload);

                var createAction = actionGroupResponse.actionGroup.subElements.Items.First() as CreateAction;

                if (createAction == null)
                {
                    Console.WriteLine("Result does not include a CreateAction.");
                }
                else
                {
                    var proposalLiteral = createAction.actionSentence as elm.Instance;
                    if (proposalLiteral == null)
                    {
                        Console.WriteLine("Resulting CreateAction does not have an ELM Instance as the Action Sentence.");
                    }
                    else
                    {
						if (proposalLiteral.classType.Name != "SubstanceAdministrationProposal")
                        {
                            Console.WriteLine("Resulting proposal is not a substance administration proposal");
                        }
                        else
                        {
                            Console.WriteLine("Substance Administration Proposed: {0}.", (proposalLiteral.element.Single(e => e.name == "substanceAdministrationGeneralPurpose").value as elm.Code).display);
                        }
                    }
                }
            }
            else
            {
                Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
//.........这里部分代码省略.........
开发者ID:GuntherM1466,项目名称:healthedecisions,代码行数:101,代码来源:Program.cs

示例15: When_POST_typed_XML_content_can_be_read

 public void When_POST_typed_XML_content_can_be_read()
 {
     var reqModel = new SomeModel
     {
         AnInteger = 2,
         AString = "hello"
     };
     var client = new HttpClient();
     client.PostAsXmlAsync(_baseAddress + "Test", reqModel);
     TestController.OnPost(req =>
     {
         var recModel = req.Content.ReadAsAsync<SomeModel>().Result;
         Assert.Equal(reqModel.AnInteger, recModel.AnInteger);
         Assert.Equal(reqModel.AString, recModel.AString);
         return new HttpResponseMessage();
     });
 }
开发者ID:pmhsfelix,项目名称:Eowin.AzureServiceBusRelay.Server,代码行数:17,代码来源:IntegrationTests.cs


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