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


C# RestRequest.AddBody方法代码示例

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


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

示例1: RegisterAsync

		public static async Task<JsonResponse> RegisterAsync(string name, string email, string password, string studentnumber)
		{
			using (var client = new RestClient(new Uri(URL)))
			{
				try
				{
					var request = new RestRequest("register.php", Method.POST);
					request.AddBody(new { name, email, password, studentnumber });
					var result = await client.Execute(request);

					var data = Encoding.UTF8.GetString(result.RawBytes, 0, result.RawBytes.Length);
					return JsonConvert.DeserializeObject<JsonResponse>(data);
				}
				catch (Exception)
				{
					return new JsonResponse { success = 0, message = "Unknown error" };
				}
			}
		}
开发者ID:tronicek,项目名称:GymIS,代码行数:19,代码来源:GymServices.cs

示例2: GetAssistance

		public static async Task<IList<AssistanceViewModel>> GetAssistance(string email)
		{
			using (var client = new RestClient(new Uri(URL)))
			{
				try
				{
					var request = new RestRequest("getAssistance.php", Method.POST);
					request.AddBody(new { email });
					var result = await client.Execute(request);

					var data = Encoding.UTF8.GetString(result.RawBytes, 0, result.RawBytes.Length);
					var response = JsonConvert.DeserializeAnonymousType(data, new { assistance = default(List<AssistanceViewModel>) });
					return response.assistance;
				}
				catch (Exception)
				{
					return new List<AssistanceViewModel>();
				}
			}
		}
开发者ID:tronicek,项目名称:GymIS,代码行数:20,代码来源:GymServices.cs

示例3: CallMethodAsync

        private async Task CallMethodAsync(string method, string customerId, HttpMethod httpMethod, object data)
        {
            var request = new RestRequest(method)
            {
                Method = httpMethod,
                Serializer = new SerializerWrapper(this._jsonSerializer)
            };
            
            if (customerId != null)
            {
                request.AddUrlSegment(@"customer_id", customerId);
            }
            request.AddBody(data);

            var response = await this._client.Execute(request).ConfigureAwait(false);
            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw new CustomerIoApiException(response.StatusCode);
            }
        }
开发者ID:ATLCTO,项目名称:CustomerIOSharp,代码行数:20,代码来源:CustomerIO.cs

示例4: MarkAssistance

		public static async Task<JsonResponse> MarkAssistance(string email)
		{
			var day = DateTime.Now.Day;
			using (var client = new RestClient(new Uri(URL)))
			{
				try
				{
					var request = new RestRequest("updateAssistance.php", Method.POST);
					request.AddBody(new { email, day });
					var result = await client.Execute(request);

					var data = Encoding.UTF8.GetString(result.RawBytes, 0, result.RawBytes.Length);
					data = data.Substring(data.IndexOf("]}", StringComparison.Ordinal) + 2);
					var response = JsonConvert.DeserializeAnonymousType(data, new { assistance = default(List<AssistanceViewModel>) });
					return JsonConvert.DeserializeObject<JsonResponse>(data);
				}
				catch (Exception)
				{
					return new JsonResponse { success = 0, message = "Unknown error" };
				}
			}
		}
开发者ID:tronicek,项目名称:GymIS,代码行数:22,代码来源:GymServices.cs

示例5: GetTrainingPlans

		public static async Task<IDictionary<string, IList<TrainingPlanViewModel>>> GetTrainingPlans(string email)
		{
			using (var client = new RestClient(new Uri(URL)))
			{
				try
				{
					var request = new RestRequest("getPlan.php", Method.POST);
					request.AddBody(new { email });
					var result = await client.Execute(request);

					var data = Encoding.UTF8.GetString(result.RawBytes, 0, result.RawBytes.Length);
					return JsonConvert.DeserializeObject<IDictionary<string, IList<TrainingPlanViewModel>>>(data);
				}
				catch (Exception)
				{
					return new Dictionary<string, IList<TrainingPlanViewModel>>();
				}
			}
		}
开发者ID:tronicek,项目名称:GymIS,代码行数:19,代码来源:GymServices.cs

示例6: LikePostAsync

        /// <summary>
        /// Toggles the like of the current post on the api.
        /// </summary>
        public async Task LikePostAsync(Post post)
        {
            var like = new Like
            {
                PostId = post.Id,
                UserIdentifier = DeviceUtils.DeviceId
            };

            using (var client = new RestClient("http://localhost:55298/api/"))
            {
                var request = new RestRequest("likes", Method.POST);
                request.AddBody(like);

                var result = await client.Execute(request);

                if (result.StatusCode == System.Net.HttpStatusCode.Created)
                {
                    post.Likes++;
                }
                else
                {
                    post.Likes--;
                }
            }
        }
开发者ID:danielbeckmann,项目名称:DotNETJumpStart,代码行数:28,代码来源:MainViewModel.cs


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