本文整理汇总了C#中RestSharp.Portable.RestRequest类的典型用法代码示例。如果您正苦于以下问题:C# RestRequest类的具体用法?C# RestRequest怎么用?C# RestRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RestRequest类属于RestSharp.Portable命名空间,在下文中一共展示了RestRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: App
public App()
{
this.serializer = new JsonSerializer ();
this.result = JsonConvert.DeserializeObject ("{ \"auth\":\"12345\"}")
as Dictionary<string, string>;
this.restClient = new RestClient ();
var request = new RestRequest (new Uri ("http://google.com"), HttpMethod.Get);
this.httpContent = restClient.GetContent (request);
this.imageButton = new ImageButton();
this.imageButton.Text = "Image Text";
this.imageButton.Source = "icon.png";
this.checkbox = new CheckBox ();
this.checkbox.Checked = true;
// The root page of your application
MainPage = new ContentPage {
Content = new StackLayout {
VerticalOptions = LayoutOptions.Center,
Children = {
new Label {
XAlign = TextAlignment.Center,
Text = "Welcome to Xamarin Forms!"
}
}
}
};
}
示例2: Get
public async Task<Club> Get(int id)
{
var request = new RestRequest(EndPoint + "/{id}", Method.GET);
request.AddParameter("id", id, ParameterType.UrlSegment);
var response = await _client.RestClient.Execute<Club>(request);
return response.Data;
}
示例3: Get
public async Task<Activity> Get(long activityId, bool includeAllEfforts = true)
{
var request = new RestRequest(EndPoint + "/{id}", Method.GET);
request.AddParameter("id", activityId, ParameterType.UrlSegment);
var response = await _client.RestClient.Execute<Activity>(request);
return response.Data;
}
示例4: ExecuteHttpRequest
/// <summary>
/// Executes a call to a web method without any persistence.
/// </summary>
/// <param name="restRequest">the <see cref="RestRequest"/></param>
/// <param name="attempsCount">the current attemp number</param>
/// <returns>The content of the </returns>
public virtual async Task<Tuple<byte[], double>> ExecuteHttpRequest(RestRequest restRequest, int attempsCount = 0)
{
attempsCount++;
var callType = restRequest.Method.ToString();
var resource = client.BuildUri(restRequest).AbsoluteUri;
Debug("Running the HTTP '" + callType + "' request '" + resource + "'");
var start = TimeSpan.FromTicks(DateTime.Now.Ticks);
var rawResponse = await client.Execute(restRequest);
var end = TimeSpan.FromTicks(DateTime.Now.Ticks);
var responseTimeInMs = (end - start).TotalMilliseconds;
var data = rawResponse.RawBytes;
var tuple = new Tuple<byte[], double>(data, responseTimeInMs);
var statusCode = rawResponse.StatusCode;
Debug("The call to the HTTP " + callType + " request '" + resource + "' took " + responseTimeInMs + " ms and returned the status code '" + statusCode + "'");
if (statusCode != HttpStatusCode.OK)
{
if (attempsCount < M4MBaseWebServiceCaller.ATTEMPTS_COUNT_MAX)
{
tuple = await ExecuteHttpRequest(restRequest, attempsCount);
}
else
{
OnHttpStatusCodeNotOk(resource, statusCode);
}
}
return tuple;
}
示例5: CreateAccountInfoRequest
public RestRequest CreateAccountInfoRequest()
{
var request = new RestRequest("{version}/account/info", HttpMethod.Get);
request.AddParameter("version", _version, ParameterType.UrlSegment);
return request;
}
示例6: CreateAccessTokenRequest
public RestRequest CreateAccessTokenRequest()
{
var request = new RestRequest("{version}/oauth/access_token", HttpMethod.Get);
request.AddParameter("version", _version, ParameterType.UrlSegment);
return request;
}
示例7: GetPublicationsIds
public PubMedPublicationIdsResult GetPublicationsIds(PubMedQueryFilter filter)
{
var restClient = new RestClient(ServiceURLs.ESearchBaseURL);
var restRequest = new RestRequest();
restRequest.AddParameter("db", databaseName, ParameterType.QueryString);
restRequest.AddParameter("retmode", "json", ParameterType.QueryString);
restRequest.AddParameter("retstart", (filter.Skip * filter.Take), ParameterType.QueryString);
restRequest.AddParameter("term", filter.Query, ParameterType.QueryString);
restRequest.AddParameter("retmax", filter.Take, ParameterType.QueryString);
if (filter.RelDate != DateTime.MinValue)
{
var pmDate = PubMedDateOperations.DatetimeToPubMedDate(filter.RelDate);
restRequest.AddParameter("reldate", pmDate, ParameterType.QueryString);
}
var waitTime = PubMedThrottler.GetWaitTime();
Thread.Sleep(waitTime);
var response = restClient.Execute<PubMedResponse>(restRequest).Result;
if (response.Data == null)
throw new Exception("No Response From The Server");
var result = new PubMedPublicationIdsResult();
result.PubMedIdCollection = new List<string>();
response.Data.esearchresult.idlist.ForEach(r => result.PubMedIdCollection.Add(r));
return result;
}
示例8: Register
public int Register(string password)
{
var request = new RestRequest("api/Register", HttpMethod.Post);
request.AddParameter("DeviceId", _deviceId);
request.AddParameter("Password", password);
return Execute<int>(request);
}
示例9: Login
public bool Login(string password)
{
var request = new RestRequest(ApiUris.Login, HttpMethod.Post);
request.AddParameter("DeviceId", _deviceId);
request.AddParameter("Password", password);
_sessionId = Execute<string>(request);
return _sessionId != null;
}
示例10: GetUsuarios
public async Task<ICollection<UsuarioModel>> GetUsuarios()
{
var request = new RestRequest("Usuario") {Method = Method.GET};
var response = await client.Execute<ICollection<UsuarioModel>>(request);
if (response.IsSuccess)
return response.Data;
return null;
}
示例11: Explore
public async Task<List<SegmentSummary>> Explore(LatLng southWest, LatLng northEast, ActivityType activityType = ActivityType.Ride)
{
var request = new RestRequest(EndPoint + "/explore", Method.GET);
request.AddParameter("bounds",
string.Format("{0},{1},{2},{3}", southWest.Latitude.ToString(CultureInfo.InvariantCulture), southWest.Longitude.ToString(CultureInfo.InvariantCulture),
northEast.Latitude.ToString(CultureInfo.InvariantCulture), northEast.Longitude.ToString(CultureInfo.InvariantCulture)));
var response = await _client.RestClient.Execute<SegmentCollection>(request);
return response.Data.Segments;
}
示例12: AddUsuario
public async Task<UsuarioModel> AddUsuario(UsuarioModel usuario)
{
var request = new RestRequest("Usuario")
{
Method = Method.POST //Otra forma de hacerlo
};
request.AddJsonBody(usuario);
var response = await client.Execute<UsuarioModel>(request);
return response.IsSuccess ? response.Data : null;
}
示例13: CreateCountriesRequest
public static RestRequest CreateCountriesRequest(int page, int countriesPerPage, RequestFormat format)
{
var restReq = new RestRequest(HttpMethod.Get);
restReq.AddQueryParameter("format", format.ToString());
restReq.AddQueryParameter("page", page);
restReq.AddQueryParameter("per_page", countriesPerPage);
return restReq;
}
示例14: AddMensaje
public async Task<MensajeModel> AddMensaje(MensajeModel mensaje)
{
var request = new RestRequest("Mensaje");
request.Method = Method.POST;
request.AddJsonBody(mensaje);
var response = await client.Execute<MensajeModel>(request);
if (response.IsSuccess) return response.Data;
return null;
}
示例15: GetUsuariosId
public async Task<UsuarioModel> GetUsuariosId(int id)
{
var request = new RestRequest("Usuario");
request.Method = Method.GET;
request.AddQueryParameter("id", id);
var response = await client.Execute<UsuarioModel>(request);
if (response.IsSuccess)
return response.Data;
return null;
}