本文整理汇总了C#中RestSharp.RestClient.ExecuteTaskAsync方法的典型用法代码示例。如果您正苦于以下问题:C# RestClient.ExecuteTaskAsync方法的具体用法?C# RestClient.ExecuteTaskAsync怎么用?C# RestClient.ExecuteTaskAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RestSharp.RestClient
的用法示例。
在下文中一共展示了RestClient.ExecuteTaskAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UploadImage
private async Task<IRestResponse> UploadImage(Bitmap curImage, string filename)
{
using (var memoryStream = new MemoryStream())
{
var codecInfo = GetEncoder(imageFormatType);
if (codecInfo.FormatDescription == "JPEG")
curImage.Save(memoryStream, codecInfo, imageEncoderParameters);
else
curImage.Save(memoryStream, imageFormatType);
var restClient = new RestClient("http://daash.pw/cgi-bin/upload.pl");
var request = new RestRequest(Method.POST);
request.AddParameter("key", uploadKey);
request.AddFileBytes("fileToUpload0", memoryStream.ToArray(), filename, "multipart/form-data");
try
{
return await restClient.ExecuteTaskAsync(request);
}
catch (Exception)
{
return null;
}
}
}
示例2: CheckStatus
private async Task<bool> CheckStatus()
{
var restClient = new RestClient(@"https://api.test.nordnet.se/next/1");
Task<IRestResponse<DummyServiceStatus>> restResponse = restClient.ExecuteTaskAsync<DummyServiceStatus>(new RestRequest(Method.GET));
IRestResponse<DummyServiceStatus> response = await restResponse;
return response.Data.SystemRunning;
}
示例3: download
static private async Task<Images> download(string domain, string path, string pattern)
{
var result = new Images();
var client = new RestClient(domain);
var restTasks = new List<Task<IRestResponse>>();
var response = client.Get(new RestRequest(path, Method.GET));
foreach (Match match in Regex.Matches(response.Content, pattern))
{
string fileName = match.Captures[0].Value.Replace(">", "");
result.Add(fileName, 0);
if (!File.Exists(baseDir(path) + "\\" + fileName))
{
var img = new RestRequest(path + fileName, Method.GET);
img.AddParameter("fileName", fileName);
restTasks.Add(client.ExecuteTaskAsync(img));
}
}
foreach (var restTask in restTasks)
{
response = await restTask;
string fileName = response.Request.Parameters[0].Value.ToString();
result[fileName] = (int)response.StatusCode;
if (response.StatusCode == HttpStatusCode.OK)
{
var fs = File.Create(baseDir(path) + "\\" + fileName);
await fs.WriteAsync(response.RawBytes, 0, response.RawBytes.Length);
fs.Close();
}
}
return result;
}
示例4: Request
protected async Task<dynamic> Request(string @base, string endpoint, IEnumerable<KeyValuePair<string, string>> @params = null, bool userless = true, Method httpMethod = Method.GET)
{
try
{
var client = new RestClient(@base);
var request = new RestRequest(endpoint, httpMethod);
var cancellationTokenSource = new CancellationTokenSource();
if (@params != null)
{
foreach (var param in @params)
{
request.AddParameter(param.Key, param.Value);
}
}
var response = await client.ExecuteTaskAsync(request, cancellationTokenSource.Token);
if (response.ResponseStatus == ResponseStatus.Completed)
{
dynamic @object = JsonConvert.DeserializeObject<ExpandoObject>(response.Content, _converter);
return @object;
}
}
catch (Exception e)
{
_logger.Error(e.Message);
}
return null;
}
示例5: bttvEmotes
public static async void bttvEmotes()
{
MainForm form = MainForm.form;
var client = new RestClient("https://cdn.betterttv.net/");
var request = new RestRequest("emotes/emotes.json", Method.GET);
var obj = await client.ExecuteTaskAsync(request);
try
{
var paObj = JArray.Parse(obj.Content);
foreach (JObject j in paObj)
{
if (form.chats[MainForm.form.tabControl1.SelectedIndex].richTextBoxInput.Text.Contains((string)j["regex"]))
{
var request2 = WebRequest.Create("https:" + (string)j["url"]);
using (var response = request2.GetResponse())
using (var stream = response.GetResponseStream())
{
Image img = Bitmap.FromStream(stream);
MainForm.form.TextToImg((string)j["regex"], img);
}
break;
}
}
}
catch
{
Console.WriteLine("timeout");
Console.WriteLine(obj.Content);
}
}
示例6: ExecuteTaskAsyncAwaitTest
public async void ExecuteTaskAsyncAwaitTest()
{
var restClient = new RestClient(@"https://api.test.nordnet.se/next/1");
Task<IRestResponse<DummyServiceStatus>> restResponse = restClient.ExecuteTaskAsync<DummyServiceStatus>(new RestRequest(Method.GET));
IRestResponse<DummyServiceStatus> response = await restResponse;
Assert.IsInstanceOf<DummyServiceStatus>(response.Data);
Assert.IsNotNull(response.Data.Timestamp);
}
示例7: GetGame
public static async Task<string> GetGame(string channel)
{
string game = null;
var client = new RestClient("https://api.twitch.tv/kraken");
var request = new RestRequest("/streams/{channel}", Method.GET);
request.AddParameter("channel", channel, ParameterType.UrlSegment);
var cancellationTokenSource = new CancellationTokenSource();
var result = await client.ExecuteTaskAsync(request, cancellationTokenSource.Token);
var pResult = JObject.Parse(result.Content);
game = (string)pResult["stream"]["game"];
return game;
}
示例8: GetMoviesAsync
/// <summary>
/// Get list of movies regarding an optional search parameter, a maximum number of movies per page, a page number (for pagination) and a cancellation token
/// </summary>
/// <param name="searchParameter">Search parameter</param>
/// <param name="maxMoviesPerPage">MaxMoviesPerPage</param>
/// <param name="pageNumberToLoad">Page number to load</param>
/// <param name="cancellationToken">cancellationToken</param>
public async Task<Tuple<IEnumerable<MovieShortDetails>, IEnumerable<Exception>>> GetMoviesAsync(
string searchParameter,
int maxMoviesPerPage,
int pageNumberToLoad,
CancellationTokenSource cancellationToken)
{
var client = new RestClient(Constants.YtsApiEndpoint);
var request = new RestRequest("/{segment}", Method.GET);
request.AddUrlSegment("segment", "list_movies.json");
request.AddParameter("limit", maxMoviesPerPage);
request.AddParameter("page", pageNumberToLoad);
if (String.IsNullOrEmpty(searchParameter))
{
request.AddParameter("sort_by", "like_count");
}
else
{
request.AddParameter("query_term", searchParameter);
}
List<Exception> ex = new List<Exception>();
WrapperMovieShortDetails results = new WrapperMovieShortDetails();
try
{
IRestResponse response = await client.ExecuteTaskAsync(request, cancellationToken.Token);
if (response != null)
{
results =
JsonConvert.DeserializeObject<WrapperMovieShortDetails>(response.Content);
}
}
catch (TaskCanceledException e)
{
ex.Add(e);
}
catch (WebException e)
{
ex.Add(e);
}
catch (Exception e)
{
ex.Add(e);
}
if (results != null && results.Data != null && results.Data.Movies != null)
{
return new Tuple<IEnumerable<MovieShortDetails>, IEnumerable<Exception>>(results.Data.Movies, ex);
}
return new Tuple<IEnumerable<MovieShortDetails>, IEnumerable<Exception>>(null, ex);
}
示例9: GetPlayerInfo
public static async Task<PlayerInfo> GetPlayerInfo(string id)
{
PlayerInfo player = new PlayerInfo();
var client = new RestClient("http://www.speedrun.com/api/v1/");
var request = new RestRequest("users/{id}", Method.GET);
request.AddParameter("id", id, ParameterType.UrlSegment);
var cancellationTokenSource = new CancellationTokenSource();
var obj = await client.ExecuteTaskAsync(request, cancellationTokenSource.Token);
var pObj = JObject.Parse(obj.Content);
player.playerName = (string)pObj["data"]["names"]["international"];
player.playerStream = (string)pObj["data"]["twitch"]["uri"];
return player;
}
示例10: GetGameID
public static async Task<string> GetGameID(string game)
{
string id = null;
var client = new RestClient("http://www.speedrun.com/api/v1/");
var request = new RestRequest("games?name={game}", Method.GET);
request.AddParameter("game", game, ParameterType.UrlSegment);
request.AddParameter("max", 1);
var cancellationTokenSource = new CancellationTokenSource();
var obj1 = await client.ExecuteTaskAsync(request, cancellationTokenSource.Token);
var pObj1 = JObject.Parse(obj1.Content);
id = (string)pObj1["data"][0]["id"];
return id;
}
示例11: ExecuteRequestAsync
public async Task<Current> ExecuteRequestAsync()
{
var client = new RestClient(url);
var request = new RestRequest();
response = await client.ExecuteTaskAsync(request);
XmlSerializer serializer = new XmlSerializer(typeof(Current));
Current objCurrent;
TextReader sr = new StringReader(response.Content);
objCurrent = (Current)serializer.Deserialize(sr);
return objCurrent;
}
示例12: SunMoonRequestAsync
// REST for Sun/Moon Conditions - Async
public async Task<S_Response> SunMoonRequestAsync()
{
var client = new RestClient(url);
var request = new RestRequest();
response = await client.ExecuteTaskAsync(request);
XmlSerializer serializer = new XmlSerializer(typeof(S_Response));
S_Response objRss;
TextReader sr = new StringReader(response.Content);
objRss = (S_Response)serializer.Deserialize(sr);
return objRss;
}
示例13: Get
public async Task<string> Get()
{
var instance = await Cluster.FindServiceInstanceAsync("ConsulDemoService1API");
var url = $"http://{instance.Address.ToLower()}:{instance.Port}";
var client = new RestClient(url);
var request = new RestRequest("/ping");
var response = await client.ExecuteTaskAsync(request);
return $"Service 1 at {url} returns {response.StatusCode} with {response.Content}";
}
示例14: ExecuteRequestAsync
public async Task<Weatherdata> ExecuteRequestAsync()
{
var client = new RestClient (url);
var request = new RestRequest ();
response = await client.ExecuteTaskAsync (request);
XmlSerializer serializer = new XmlSerializer (typeof(Weatherdata));
Weatherdata objRss;
TextReader sr = new StringReader (response.Content);
objRss = (Weatherdata)serializer.Deserialize (sr);
return objRss;
}
示例15: Send
private async Task<SendResult> Send(MaloneRestRequest request, CancellationToken token)
{
var result = new SendResult();
var client = new RestClient(request.BaseUrl)
{
FollowRedirects = false
};
result.SentAt = DateTimeOffset.UtcNow;
var response = await client.ExecuteTaskAsync(request, token);
result.ReceivedAt = DateTimeOffset.UtcNow;
result.Response = response;
return result;
}