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


C# RestClient.PostAsync方法代码示例

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


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

示例1: Should_post_bson

        public async Task Should_post_bson()
        {
            using (var server = TestServer.Create<Startup>())
            {
                var restClient = new RestClient(server.HttpClient);

                var id = await restClient.PostAsync<int>("/api/foos", new Foo(), MediaTypes.ApplicationJson, MediaTypes.ApplicationJson);

                id.ShouldEqual(1);
            }
        }
开发者ID:DIPSASA,项目名称:RestClient,代码行数:11,代码来源:BsonTests.cs

示例2: OnNavigatedTo

        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (e.Parameter is VoiceCommandActivatedEventArgs)
            {
                var args = e.Parameter as VoiceCommandActivatedEventArgs;
                var speechRecognitionResult = args.Result;

                var command = speechRecognitionResult.Text;
                statusMessage.Text = string.Format("Esecuzione del comando {0}...", command);

                var action = speechRecognitionResult.RulePath.FirstOrDefault();
                var turnOn = (action == "turnOn");

                var semanticProperties = speechRecognitionResult.SemanticInterpretation.Properties;

                // Figure out the color.
                var color = string.Empty;
                if (semanticProperties.ContainsKey("colors"))
                    color = semanticProperties["colors"][0];

                var rgb = this.GetRgb(color, turnOn);

                using (var client = new RestClient(SERVICE_URL))
                {
                    try
                    {
                        await client.PostAsync("led/set", rgb);
                        statusMessage.Text = "Comando inviato con successo.";
                    }
                    catch (Exception ex)
                    {
                        statusMessage.Text = "Errore durante l'invio del comando: " + ex.Message;
                    }
                }
            }
        }
开发者ID:Robotonics,项目名称:IoTHelpers,代码行数:36,代码来源:MainPage.xaml.cs

示例3: CreateResource_Succeeds

        public async Task CreateResource_Succeeds()
        {
            // Arrange
            var client = new RestClient(_baseAddress);
            //var data = _mock.Object;
            var data = new Post { Title = "foo", Body = "bar", UserId = "1" };

            // Act
            var response = await client.PostAsync(new Uri("posts", UriKind.Relative), data);

            // Assert
            Assert.IsTrue(response.Succeeded);
            Assert.AreEqual(response.Data.Title, data.Title);
            Assert.AreEqual(response.Data.Body, data.Body);
            Assert.AreEqual(response.Data.UserId, data.UserId);

            //mockService.Verify(x => x.GetAll(), Times.Once());
        }
开发者ID:stevenvolckaert,项目名称:autodesk-inventor-powertools,代码行数:18,代码来源:RestClientFixture.cs

示例4: Should_post_json_with_parameters

        public async Task Should_post_json_with_parameters()
        {
            using (var server = TestServer.Create<Startup>())
            {
                var restClient = new RestClient(server.HttpClient);
                var parameters = new Dictionary<string, string> { { "param1", "value1" }, { "param2", "value2" } };

                var id = await restClient.PostAsync<int>("/api/foos", new Foo(), MediaTypes.ApplicationJson, null, parameters);

                id.ShouldEqual(1);
            }
        }
开发者ID:DIPSASA,项目名称:RestClient,代码行数:12,代码来源:Tests.cs

示例5: Should_post_form_url_encoded_content

        public async Task Should_post_form_url_encoded_content()
        {
            using (var server = TestServer.Create<Startup>())
            {
                var restClient = new RestClient(server.HttpClient);
                var values = new List<KeyValuePair<string, string>> { new KeyValuePair<string, string>("SomeInt", "1") };
                var content = new FormUrlEncodedContent(values);

                var id = await restClient.PostAsync<int>("/api/foos", content, MediaTypes.FormUrlEncoded, null);

                id.ShouldEqual(1);
            }
        }
开发者ID:DIPSASA,项目名称:RestClient,代码行数:13,代码来源:Tests.cs

示例6: SendRoverCommandAsync

 private async Task SendRoverCommandAsync(RoverMovementType command)
 {
     using (var client = new RestClient(SERVICE_URL))
     {
         try
         {
             await client.PostAsync("rover/move", new RoverMovement { Movement = command });
         }
         catch (Exception ex)
         {
             var dialog = new MessageDialog($"Error sending commnad: {ex.Message}");
             await dialog.ShowAsync();
         }
     }
 }
开发者ID:Robotonics,项目名称:IoTHelpers,代码行数:15,代码来源:MainPage.xaml.cs

示例7: SendJukeboxCommandAsync

 private async Task SendJukeboxCommandAsync(string command)
 {
     using (var client = new RestClient(SERVICE_URL))
     {
         try
         {
             await client.PostAsync($"jukebox/{command}");
         }
         catch (Exception ex)
         {
             var dialog = new MessageDialog($"Error sending commnad: {ex.Message}");
             await dialog.ShowAsync();
         }
     }
 }
开发者ID:Robotonics,项目名称:IoTHelpers,代码行数:15,代码来源:MainPage.xaml.cs


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