本文整理汇总了C#中RestSharp.RestClient.Get方法的典型用法代码示例。如果您正苦于以下问题:C# RestClient.Get方法的具体用法?C# RestClient.Get怎么用?C# RestClient.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RestSharp.RestClient
的用法示例。
在下文中一共展示了RestClient.Get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Get
public ApiStepResult Get(Guid stepId, string rootPath, string resource)
{
DateTime start = DateTime.Now;
var client = new RestClient(rootPath);
IRestResponse restResponse = client.Get(new RestRequest(resource));
TimeSpan span = DateTime.Now - start;
return new ApiStepResult(stepId, restResponse.StatusCode, restResponse.Content, _timeProvider.Now(),
span.TotalMilliseconds);
}
示例2: Translate
public string Translate(string resource, string locale, string targetLocale)
{
var restClient = new RestClient(_baseUrl);
var request = new RestRequest("Translate") { OnBeforeDeserialization = resp => { resp.ContentType = "application/json"; } };
request.AddQueryParameter("text", resource);
request.AddQueryParameter("from", locale);
request.AddQueryParameter("to", targetLocale);
request.AddHeader("Authorization", $"Bearer {_accessToken.access_token}");
var response = restClient.Get(request);
return response.Content.Replace("\"", "");
}
示例3: Main
static void Main(string[] args)
{
string[] API = { "http://search.twitter.com/search.json?q=wcf service", "http://themoneyconverter.com/rss-feed/JMD/rss.xml" };
Channel channel = new Channel();
var response = "";
using (WebClient client = new WebClient())
{
response = client.DownloadString(new Uri(API[1]));
}
Console.WriteLine("{0}",response);
Console.Read();
// Create the client for parsing
var parser = new RestClient();
// Setup the baseUrl for the API
parser.BaseUrl = "http://search.twitter.com";
// Create a request
var request = new RestRequest();
// This a fix for
request.AddHeader("Content-Type", "application/json");
// Setup the resource or query to make the API call
request.Resource = "search.json?q=wcf service";
var responses = parser.Get<TSearch>(request);
int x = 0;
Console.WriteLine("{0}",responses.Data.ResultsPerPage);
Console.Read();
}
示例4: Run
public IRestResponse Run(Step step, ScenarioContext context)
{
var apiPostStep = (ApiGetStep)step;
var client = new RestClient(apiPostStep.Host);
var restRequest = BuildRequest(apiPostStep);
return client.Get(restRequest);
}
示例5: GetList
public static void GetList(string format)
{
var c = new RestClient(String.Format("{0}?format={1}", baseUrl, format));
var resp = c.Get(CreateRequest(Method.GET, format));
if (!Models.Any())
WriteResult("GET LIST", resp);
Models.Clear();
if (string.IsNullOrEmpty(resp.Content))
{
return;
}
var ds = format == "json" ? new JsonDeserializer() : new XmlDeserializer() as IDeserializer;
if (format != "json")
resp.Content = resp.Content.Substring(1);
var obj = ds.Deserialize<List<UserModel>>(resp);
if (obj != null)
{
Models.AddRange(obj);
}
}
示例6: 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;
}
示例7: DoJsonTest
private double DoJsonTest(int threadId, int numberOfRequests)
{
var client = new RestClient("http://localhost:4472/api");
var request = new RestRequest("coffees/", Method.GET);
request.AddHeader("accept", "application/json");
long[] times = new long[numberOfRequests];
for (int i = 0; i < numberOfRequests; i++)
{
Stopwatch watch = new Stopwatch();
watch.Start();
var response = client.Get<List<Coffee>>(request);
watch.Stop();
Console.WriteLine("Thread {0}, {1} ms, {2} bytes, {3} status code", threadId, watch.ElapsedMilliseconds,
response.RawBytes.Length, response.StatusCode);
if (i > 0)
{
times[i] = watch.ElapsedMilliseconds;
}
}
return times.Average();
}
示例8: List
public Package[] List()
{
var client = new RestClient(BaseUri)
{
Authenticator = new HttpBasicAuthenticator(Username, Password)
};
var request = new RestRequest($"/rest/api/1.0/projects/{ProjectKey}/repos", Method.GET);
IRestResponse<StashProjectRepos> response;
try
{
response = client.Get<StashProjectRepos>(request);
}
catch (Exception)
{
return new Package[0];
}
if (response == null || response.Data == null || response.Data.Values == null || !response.Data.Values.Any())
{
return new Package[0];
}
Packages = response.Data.Values.Select(repo => new Package
{
Name = repo.Slug,
Url = SshInsteadOfHttp ? MakeSshUri(repo.Slug) : MakeHttpUri(repo.Slug)
}).ToArray();
return Packages;
}
示例9: Index
// GET: User
public ViewResult Index()
{
var token = _sessionHelper.GetToken();
if (token == "SessionIsNull")
return View("ErorrForm", new ErorrMessage { Message = "Нет токена" });
var clientUser = new RestClient(SiteConn.UserWebApiServer);
var getUser = new RestRequest($"User");
getUser.AddHeader("Authorization", token);
getUser.AddHeader("Content-Type", "application / json");
getUser.AddParameter("login", _sessionHelper.GetLogin());
var response = clientUser.Get<UserInfo>(getUser);
if(response.StatusCode == 0)
return View("ErorrForm", new ErorrMessage {Message = "Нет данных для отображения" });
if (response.Data == null)
return View("ErorrForm", new ErorrMessage { Message = "Нет данных для отображения" });
return View(response.Data);
}
示例10: GetStockData
public IEnumerable<IStockTicker> GetStockData(string symbol, int days)
{
try
{
// create the REST client
var client = new RestClient(STOCK_DATA_BASE_URI);
// calculate the start from date
//var fromDate = DateTime.Now.Substract(TimeSpan.FromDays(days));
// create the REST request
var request = new RestRequest().AddQueryParameter(STOCK_DATA_SYMBOL_PARAM, symbol)
//.AddQueryParameter(STOCK_DATA_FROM_MONTH_PARAM, (fromDate.Month - 1).ToString())
//.AddQueryParameter(STOCK_DATA_FROM_DAYS_PARAM, fromDate.Day.ToString())
//.AddQueryParameter(STOCK_DATA_FROM_YEAR_PARAM, fromDate.Year.ToString())
//.AddQueryParameter(STOCK_DATA_TO_MONTH_PARAM, (DateTime.Now.Month - 1).ToString())
//.AddQueryParameter(STOCK_DATA_TO_DAYS_PARAM, DateTime.Now.Day.ToString())
//.AddQueryParameter(STOCK_DATA_TO_YEAR_PARAM, DateTime.Now.Year.ToString())
.AddQueryParameter(STOCK_DATA_INTERVAL_PARAM, "d");
// execute request
var response = client.Get(request);
using (var textReader = new StringReader(response.Content))
using (var csvReader = new CsvReader(textReader))
{
return csvReader.GetRecords<StockTicker>()
.Take(days)
.ToList();
}
}
catch (Exception ex)
{
return new List<IStockTicker>();
}
}
示例11: LbDeserializeTest
public void LbDeserializeTest()
{
DateTime? currDate = new DateTime(2014, 1, 1);
var lbClient = new RestClient(ConfigurationManager.AppSettings["lbBaseUri"]);
var req = new RestRequest(String.Format(ConfigurationManager.AppSettings["lbCurrencyServiceUrl"], currDate.Value.ToShortDateString()), Method.GET);
var resp = lbClient.Get(req);
//====================
//var rates = new ExchangeRates();
var serializer = new XmlSerializer(typeof(ExchangeRates));
var reader = XmlReader.Create(new StringReader(resp.Content));
var rates = (ExchangeRates)serializer.Deserialize(reader);
//====================
Assert.IsNotNull(rates);
Assert.IsNotNull(rates.item);
Assert.IsTrue(rates.item.Any());
Console.WriteLine(rates.item.Count());
}
示例12: GetFundraisingPageDonations
public FundraisingPageDonations GetFundraisingPageDonations()
{
RestClient client = new RestClient("https://api.justgiving.com/0f938d22/v1/fundraising/pages/justmovies/donations");
var request = new RestRequest(Method.GET);
request.AddHeader("Accept", "application/json");
var result = client.Get<FundraisingPageDonations>(request);
return result.Data;
}
示例13: GetNoIntroSystems
private static IEnumerable<string> GetNoIntroSystems()
{
var client = new RestClient("http://datomatic.no-intro.org/?page=download&fun=xml");
string website = client.Get(new RestRequest()).Content;
var html = new HtmlDocument();
html.LoadHtml(website);
IEnumerable<string> systems = html.DocumentNode.QuerySelectorAll("select[name=sel_s] > option")
.Select(node => node.Attributes["value"].Value)
.Select(system => system.Replace(' ', '+')); //Get available select options in sel_s and replace spaces with +
return systems;
}
示例14: List
// GET: Man
public ViewResult List()
{
var client = new RestClient(SiteConn.ManWebApiServer);
var getMan = new RestRequest("Man");
getMan.AddHeader("Content-Type", "application / json");
var response = client.Get<List<Manufacturer>>(getMan);
return View(response.Data);
}
示例15: GetContent
public string GetContent(string url)
{
// Perform a GET request to the given URL
var client = new RestClient(url);
var response = client.Get(new RestRequest());
if ((int) response.StatusCode >= 400) {
throw new Exception(response.StatusDescription);
}
return response.Content;
}