本文整理汇总了C#中RestSharp.Portable.RestRequest.AddUrlSegment方法的典型用法代码示例。如果您正苦于以下问题:C# RestRequest.AddUrlSegment方法的具体用法?C# RestRequest.AddUrlSegment怎么用?C# RestRequest.AddUrlSegment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RestSharp.Portable.RestRequest
的用法示例。
在下文中一共展示了RestRequest.AddUrlSegment方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateComponentStatusAsync
public Task<Component> UpdateComponentStatusAsync(string roomId, string deviceId, bool status)
{
var request = new RestRequest("components?roomId={roomId}&deviceId={deviceId}&status={status}") {Method = HttpMethod.Put};
request.AddUrlSegment("roomId", roomId)
.AddUrlSegment("deviceId", deviceId)
.AddUrlSegment("status", status);
request.AddHeader("Content-Type", "application/json");
var task = _client.Execute<Component>(request).ContinueWith(t => t.Result.Data);
return task;
}
示例2: GetPostsAsync
/// <summary>
/// Gets the posts from the api.
/// </summary>
/// <param name="sorting">Current sorting</param>
public async Task GetPostsAsync(Sorting sorting = Sorting.Latest)
{
this.currentSorting = sorting;
using (var client = new RestClient("http://localhost:55298/api/"))
{
var request = new RestRequest("posts/{sorting}", Method.GET);
request.AddUrlSegment("sorting", sorting.ToString());
var result = await client.Execute<List<Post>>(request);
this.Posts = result.Data;
}
}
示例3: MainAsync
async static Task MainAsync(string[] args, CancellationTokenSource cts)
{
using (RestClient client = new RestClient("http://localhost:4711") { Timeout = new TimeSpan(0, 0, 10) })
{
while (!cts.Token.IsCancellationRequested)
{
if (Console.KeyAvailable)
{
var key = Console.ReadKey();
switch (key.KeyChar)
{
case 'a':
{
RestRequest request = new RestRequest("Hello", RestSharp.Portable.Method.POST);
request.AddJsonBody(new HelloRequest
{
Text = "HelloText",
Id = 1,
});
var response = await client.Execute<HelloResponse>(request);
Console.WriteLine($"Hello Response Text={response.Data.Text} Id={response.Data.Id}");
break;
}
case'b':
{
RestRequest request = new RestRequest("User/{id}", RestSharp.Portable.Method.GET);
request.AddUrlSegment("id", 1);
var response = await client.Execute<string>(request);
Console.WriteLine($"User Response Text={Encoding.UTF8.GetString(response.RawBytes)}");
break;
}
case 'c':
{
RestRequest request = new RestRequest("User/{id}", RestSharp.Portable.Method.GET);
request.AddUrlSegment("id", 666);
var response = await client.Execute(request);
Console.WriteLine($"User Response Text={Encoding.UTF8.GetString(response.RawBytes)}");
break;
}
case '\n':
cts.Cancel();
return;
}
}
else
Thread.Sleep(100);
}
}
}
示例4: 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);
}
}
示例5: GetEventRankings
public static async Task<List<List<string>>> GetEventRankings(string key)
{
var request = new RestRequest(ApiUrl.EventRankings);
request.AddUrlSegment("key", key);
return await MakeRequest<List<List<string>>>(request);
}
示例6: GetEventStats
public static Task<EventStats> GetEventStats(string key)
{
var request = new RestRequest(ApiUrl.EventStats);
request.AddUrlSegment("key", key);
return MakeRequest<EventStats>(request);
}
示例7: GetEventTeams
public static Task<List<Team>> GetEventTeams(string key)
{
var request = new RestRequest(ApiUrl.EventTeams);
request.AddUrlSegment("key", key);
return MakeRequest<List<Team>>(request);
}
示例8: GetEvents
public static Task<List<Event>> GetEvents(int year)
{
var request = new RestRequest(ApiUrl.EventList);
request.AddUrlSegment("year", year);
return MakeRequest<List<Event>>(request);
}
示例9: GetTeams
public static async Task<List<Team>> GetTeams(int page)
{
var request = new RestRequest(ApiUrl.TeamPage);
request.AddUrlSegment("page", page);
return await MakeRequest<List<Team>>(request);
}