本文整理汇总了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" };
}
}
}
示例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>();
}
}
}
示例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);
}
}
示例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" };
}
}
}
示例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>>();
}
}
}
示例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--;
}
}
}