本文整理汇总了C#中RestSharp.RestRequest.AddQueryParameter方法的典型用法代码示例。如果您正苦于以下问题:C# RestRequest.AddQueryParameter方法的具体用法?C# RestRequest.AddQueryParameter怎么用?C# RestRequest.AddQueryParameter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RestSharp.RestRequest
的用法示例。
在下文中一共展示了RestRequest.AddQueryParameter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SignIn
public RedirectResult SignIn(string login, string password, string appId,
string redirectUri, string state)
{
var client = new RestClient(SiteConn.AuthWebApiServer);
var signInRequest = new RestRequest("Auth/SignIn");
signInRequest.AddQueryParameter("login",login);
signInRequest.AddQueryParameter("password",password);
signInRequest.AddQueryParameter("appId",appId);
signInRequest.AddQueryParameter("redirectUri", redirectUri);
signInRequest.AddQueryParameter("state","666");
var response = client.Post(signInRequest);
if (response == null) return new RedirectResult(redirectUri);
//получаю куки с токеном
if (response.Cookies != null)
{
return new RedirectResult(redirectUri);
}
return null;
}
示例2: Request
public string Request(RestSharp.Method method, string endPoint, Dictionary<string,object> headers, Dictionary<string, object> parameters, Dictionary<string, object> queryParameters, string body)
{
RestClient client = new RestClient(baseURL);
RestRequest request = new RestRequest(endPoint, method);
client.Authenticator = authenticator;
foreach (var key in headers.Keys)
{
if(headers[key].GetType().ToString().StartsWith("System.Collections.Generics.List"))
{
request.AddHeader(key,JsonConvert.SerializeObject(headers[key]));
}
else
{
request.AddHeader(key,headers[key].ToString());
}
}
foreach (var key in parameters.Keys)
{
request.AddParameter(key, parameters[key]);
}
foreach (var key in queryParameters.Keys)
{
if (headers[key].GetType().ToString().StartsWith("System.Collections.Generics.List"))
{
request.AddQueryParameter(key, JsonConvert.SerializeObject(queryParameters[key]));
}
else
{
request.AddQueryParameter(key, queryParameters[key].ToString());
}
}
var response = client.Execute(request);
return response.Content;
}
示例3: 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("\"", "");
}
示例4: SignIn
public RedirectResult SignIn(string login, string password, string appId,
string redirectUri, string state)
{
var client = new RestClient("http://localhost:9999/api/");
var signInRequest = new RestRequest("Auth/SignIn");
signInRequest.AddQueryParameter("login",login);
signInRequest.AddQueryParameter("password",password);
signInRequest.AddQueryParameter("appId",appId);
signInRequest.AddQueryParameter("redirectUri", redirectUri);
signInRequest.AddQueryParameter("state","666");
var response = client.Post(signInRequest);
var url = response.ResponseUri.ToString();
var urlArr = url.Split('?', '=', '&');
var user = Auth(login, password);
if (user == null)
throw new ArgumentException("Неверная пара логин/пароль");
var app = _appDataReposytory.AppDatas.FirstOrDefault(e => e.Id.ToString() == appId);
if (app == null)
throw new Exception("Нет приложения с таким appId");
_codes.Add(urlArr[2], user.Id);
//_sessionHelper.CreateNewSession(user, app);
return new RedirectResult(url);
}
示例5: NoRecentPlay
/// <summary>
/// Check if the plexIdleTimeout has elapsed since the last play
/// </summary>
/// <returns>true if no videos were marked watched since the timer interval</returns>
public bool NoRecentPlay()
{
int plexIdleTimeout;
int.TryParse(Properties.Settings.Default.PlexIdleTimeout, out plexIdleTimeout);
if (string.IsNullOrEmpty(_user.authenticationToken))
{
throw new Exception("No authentication token.");
}
var client = new RestClient("http://localhost:32400/status/sessions/history/all");
var request = new RestRequest(Method.GET);
request.AddQueryParameter("X-Plex-Token", _user.authenticationToken);
request.AddQueryParameter("X-Plex-Container-Start", "0");
request.AddQueryParameter("X-Plex-Container-Size", "1");
IRestResponse<PlexHistoryObjects.MediaContainer> response = client.Execute<PlexHistoryObjects.MediaContainer>(request);
if (response.Data.Video != null)
{
var lastStream = response.Data.Video;
DateTime lastStreamDateTime = UnixTimeStampToDateTime(double.Parse(lastStream.ViewedAt));
TimeSpan timeSpan = DateTime.Now - lastStreamDateTime;
var msSinceLastStream = timeSpan.TotalMilliseconds;
Trace.WriteLine("Last stream: " + lastStream.GrandparentTitle + " at " +
lastStreamDateTime.ToUniversalTime());
return msSinceLastStream >= (plexIdleTimeout * Global.Minutes);
}
else
{
return true;
}
}
示例6: GetTimetable
public TimetableModel GetTimetable(string operatorName, string stopIdentifier, int numResults)
{
var request = new RestRequest("v1/timetables", Method.GET);
request.RequestFormat = RestSharp.DataFormat.Json;
request.AddQueryParameter("OperatorName", operatorName);
request.AddQueryParameter("StopIdentifier", stopIdentifier);
request.AddQueryParameter("NumResults", numResults.ToString());
var response = Client.Execute<TimetableModel>(request);
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
if (response.Data == null || response.Data.Operator == null || response.Data.StopName == null || response.Data.TimetableEntry == null)
{
return null;
}
return response.Data;
}
else
{
Logger.Instance.Write("GetTimetable", LogLevel.Medium, "Call failed with status code " + response.StatusCode);
return null;
}
}
示例7: GetObject
public object GetObject(string resourceKey, CultureInfo culture)
{
var locale = (culture ?? GetCurrentUserCulture()).ToString();
var key = $"Resource{_applicationName}|{_resourceSet}|{resourceKey}|{locale}";
return _cacheProvider.GetValue(key, () =>
{
var restRequest = new RestRequest("/api/resource") { OnBeforeDeserialization = resp => { resp.ContentType = "application/json"; } };
restRequest.AddQueryParameter("application", _applicationName);
restRequest.AddQueryParameter("resourceSet", _resourceSet);
restRequest.AddQueryParameter("resourceKey", resourceKey);
restRequest.AddQueryParameter("locale", locale);
try
{
var response = _restClient.Get<Resource>(restRequest);
if (response.ErrorMessage == "Unable to connect to the remote server")
throw new HttpConnectionException(string.Format(Errors.UnableToConnect, _restClient.BaseUrl), response.ErrorException);
if (response.StatusCode == HttpStatusCode.InternalServerError)
throw new HttpConnectionException(Errors.ServerError, response.ErrorException);
return response.Data.Value;
}
catch (Exception)
{
return resourceKey;
}
});
}
示例8: BuildRestRequestForMatchHistoryBySequenceNumber
private static IRestRequest BuildRestRequestForMatchHistoryBySequenceNumber(int sequenceNumber,
int matchesRequested)
{
var request = new RestRequest(RequestPaths.Dota2.Match.MatchHistoryBySequenceNumber);
if (sequenceNumber > 0)
request.AddQueryParameter("start_at_match_seq_num", sequenceNumber);
if (matchesRequested > 0)
request.AddQueryParameter("matches_requested", matchesRequested);
return request;
}
示例9: AuthenticateUser
/// <summary>
/// Authenticate user by given username and password.
/// </summary>
/// <param name="username">Account username or email</param>
/// <param name="password">Account password</param>
/// <returns></returns>
public TokenResult AuthenticateUser(string username, string password)
{
var request = new RestRequest();
request.Resource = "tokens";
request.Method = Method.POST;
request.AddQueryParameter("username", username);
request.AddQueryParameter("password", password);
return Execute<TokenResult>(request);
}
示例10: ExecuteQuery
public string ExecuteQuery(string input,string page)
{
var request = new RestRequest(Resource);
request.AddParameter("connectorId", ConnectorID, ParameterType.UrlSegment);
if (!String.IsNullOrEmpty(input))
request.AddQueryParameter("input", input);
if (!String.IsNullOrEmpty(page))
request.AddQueryParameter("page", page);
return Execute(request);
}
示例11: GetScheduledLeagueGames
public IEnumerable<ScheduledGame> GetScheduledLeagueGames(DateTime dateMin = default(DateTime), DateTime dateMax = default(DateTime))
{
var request = new RestRequest(RequestPaths.Dota2.League.ScheduledLeagueGames);
var defaultDateTime = default(DateTime);
if (dateMin != defaultDateTime)
request.AddQueryParameter("date_min", dateMin.ToUnixTime());
if (dateMax != defaultDateTime)
request.AddQueryParameter("date_max", dateMax.ToUnixTime());
var response = Execute<ScheduledLeagueGamesResponseWrapper>(request);
return Mapper.Map<List<ScheduledGame>>(response.Games);
}
示例12: GetGiphy
private string GetGiphy(string search)
{
var request = new RestRequest("/v1/gifs/translate", Method.GET);
request.AddQueryParameter("s", search);
request.AddQueryParameter("rating", Rating);
request.AddQueryParameter("api_key", GiphyApiKey);
var response = _client.Execute<dynamic>(request);
var url = response.Data["data"]["images"]["fixed_height"]["url"];
return url;
}
示例13: Apply
internal void Apply(RestRequest request)
{
// offset and and limit
request.AddQueryParameter("offset", _offset.ToString());
request.AddQueryParameter("limit", _limit.ToString());
// filter if needed
if (_filter != null)
_filter.Apply(request);
// marker if needed
if (_marker != null)
_marker.Apply(request);
}
示例14: Main
static void Main()
{
var client = new RestClient("http://localhost:2741/api/calculator");
var request = new RestRequest("distance", Method.POST);
request.AddQueryParameter("startX", "5");
request.AddQueryParameter("startY", "5");
request.AddQueryParameter("endX", "10");
request.AddQueryParameter("endY", "10");
RestResponse response = (RestResponse)client.Execute(request);
var content = response.Content;
Console.WriteLine(content);
}
示例15: GetMatch
public MatchDetail GetMatch(string matchId)
{
var request = new RestRequest(RequestPaths.Dota2.Match.MatchDetails, Method.GET);
request.AddQueryParameter("match_id", matchId);
var response = Execute<MatchDetailResponse>(request);
return Mapper.Map<MatchDetail>(response);
}