本文整理汇总了C#中RestSharp.RestRequest类的典型用法代码示例。如果您正苦于以下问题:C# RestRequest类的具体用法?C# RestRequest怎么用?C# RestRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RestRequest类属于RestSharp命名空间,在下文中一共展示了RestRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ActivateFeature
public string ActivateFeature(string baseSiteUrl, string user, string password, string domain)
{
if (baseSiteUrl.EndsWith("/"))
baseSiteUrl += "_api/";
else
baseSiteUrl += "/_api/";
RestClient rc = new RestClient(baseSiteUrl);
NetworkCredential nCredential = new NetworkCredential(user, password, domain);
rc.Authenticator = new NtlmAuthenticator(nCredential);
RestRequest request = new RestRequest("contextinfo?$select=FormDigestValue", Method.POST);
request.AddHeader("Accept", "application/json;odata=verbose");
request.AddHeader("Body", "");
string returnedStr = rc.Execute(request).Content;
int startPos = returnedStr.IndexOf("FormDigestValue", StringComparison.Ordinal) + 18;
int length = returnedStr.IndexOf(@""",", startPos, StringComparison.Ordinal) - startPos;
string formDigestValue = returnedStr.Substring(startPos, length);
request = new RestRequest("web/features/add('de646322-53f3-474d-96bf-0ea3670a0722',false)", Method.POST);
request.RequestFormat = DataFormat.Json;
request.AddHeader("Accept", "application/json;odata=verbose");
//request.AddHeader("Body", "");
request.AddHeader("Content-Type", "application/json;odata=verbose");
request.AddHeader("X-RequestDigest", formDigestValue);
IRestResponse response = rc.Execute(request);
string content = response.Content;
return content;
}
示例2: IsValidKey
public async Task<bool> IsValidKey(string key)
{
try
{
var client = new RestClient("http://" + _serverAdress);
var request = new RestRequest("getProductKeyValid.php", Method.GET);
request.AddParameter("productkeys_Key", key);
request.Timeout = 5000;
IRestResponse response = await client.ExecuteGetTaskAsync(request);
//only throws the exception. Let target choose what to do
if (response.ErrorException != null)
{
throw response.ErrorException;
}
var model = Newtonsoft.Json.JsonConvert.DeserializeObject<string>(response.Content);
//if string equals "1" the key is not activated yet
if (model.Equals("1"))
return true;
return false;
}
catch (Exception e)
{
return false;
}
}
示例3: CreateAccessToken
public RestRequest CreateAccessToken()
{
var request = new RestRequest(Method.GET);
request.Resource = "{version}/oauth/access_token";
request.AddParameter("version", _version, ParameterType.UrlSegment);
return request;
}
示例4: Send
/// <summary>
/// Sends the formatted messages.
/// </summary>
/// <param name="messages">The messages to send.</param>
/// <param name="succeededAction">A success action that should be called for successfully sent messages.</param>
/// <param name="failedAction">A failure action that should be called when a message send operation fails.</param>
public void Send(IEnumerable<ProviderNotificationMessage> messages,
Action<ProviderNotificationMessage> succeededAction,
Action<ProviderNotificationMessage, Exception> failedAction)
{
foreach (var message in messages)
{
try
{
// create a new rest request and add the message to the http message body
var request = new RestRequest(Method.POST);
request.AddJsonBody(message);
// send the POST request and call success action if everything went fine
_client.Post<ProviderNotificationMessage>(request);
if (succeededAction != null)
succeededAction(message);
}
catch(Exception e)
{
// if the post fails call the failedAction
if(failedAction != null)
failedAction(message, e);
}
}
}
示例5: GetCustomers
public List<Customer> GetCustomers()
{
const string resourceName = "customers";
var request = new RestRequest(resourceName, Method.GET);
var customers = Execute<CustomerList>(request).Customers;
return customers;
}
示例6: Login
//TODO
public AccessToken Login(string userName, string password, string state)
{
var client = new RestClient(@"https://api.twitch.tv/kraken/oauth2/token");
var request = new RestRequest(Method.POST);
request.AddHeader("Content-type", "application/json");
request.AddBody(
new
{
client_id = ClientID,
client_secret = ClientSecret,
grant_type = "authorization_code",
redirect = @"https://localhost",
code = /*code received from redirect*/,
state = state
});
var response = client.Execute(request);
if (response.StatusCode == HttpStatusCode.OK)
{
var result = JsonConvert.DeserializeObject<AccessToken>(response.Content);
return result;
}
return null;
}
示例7: Send
public Task<string> Send(string method, string path, string json, CancellationToken cancelToken)
{
var request = new RestRequest(path, GetMethod(method));
if (json != null)
request.AddParameter("application/json", json, ParameterType.RequestBody);
return Send(request, cancelToken);
}
示例8: GetRequest
private static RestRequest GetRequest(Method method, string resource)
{
var request = new RestRequest(method);
request.Resource = resource;
request.JsonSerializer = new RestSharpJsonNetSerializer();
return request;
}
示例9: GetCore
private Task<dynamic> GetCore(dynamic parameters, CancellationToken ct)
{
return Task<dynamic>.Factory.StartNew(() => {
this.RequiresAuthentication();
var user = Context.CurrentUser as Identity;
if (user == null)
return Negotiate.WithStatusCode(Nancy.HttpStatusCode.Unauthorized);
List<string> responses = new List<string>();
var client = new RestClient(Request.Url.SiteBase);
foreach (var device in _connection.Select<Device>())
{
var request = new RestRequest(DevicesProxyModule.PATH + "/.well-known/core", Method.GET);
request.AddUrlSegment("id", device.Id.ToString(CultureInfo.InvariantCulture));
request.AddParameter("SessionKey", user.Session.SessionKey);
var resp = client.Execute(request);
if (resp.StatusCode == HttpStatusCode.OK)
responses.Add(resp.Content);
}
var r = (Response)string.Join(",", responses);
r.ContentType = "application/link-format";
return r;
}, ct);
}
示例10: FacebookAuth
public ActionResult FacebookAuth()
{
if (Request.Params.AllKeys.Contains("code"))
{
var code = Request.Params["code"];
var client = new RestClient("https://graph.facebook.com/oauth/access_token");
var request = new RestRequest(Method.GET);
//request.AddParameter("action", "access_token");
request.AddParameter("client_id", this.ClientID);
request.AddParameter("redirect_uri", this.FacebookCallbackUrl);
request.AddParameter("client_secret", this.ClientSecret);
request.AddParameter("code", code);
var response = client.Execute(request);
var pairResponse = response.Content.Split('&');
var accessToken = pairResponse[0].Split('=')[1];
client = new RestClient("https://graph.facebook.com/me");
request = new RestRequest(Method.GET);
request.AddParameter("access_token", accessToken);
response = client.Execute(request);
JObject jObject = JObject.Parse(response.Content);
}
return RedirectToAction("Index", "Home");
}
示例11: ConfirmResource
/// <summary>
/// Confirm a newly-created subscription, pre-authorzation or one-off
/// payment. This method also checks that the resource response data includes
/// a valid signature and will throw a {SignatureException} if the signature is
/// invalid.
/// </summary>
/// <param name="requestContent">the response parameters returned by the API server</param>
/// <returns>the confirmed resource object</returns>
public ConfirmResource ConfirmResource(NameValueCollection requestContent)
{
var resource = DeserializeAndValidateRequestSignature(requestContent);
var request = new RestRequest("confirm", Method.POST);
request.RequestFormat = DataFormat.Json;
request.AddBody(
new
{
resource_id = resource.ResourceId,
resource_type = resource.ResourceType
});
var client = new RestClient
{
BaseUrl = new System.Uri(ApiClient.ApiUrl),
UserAgent = GoCardless.UserAgent
};
var serializer = new JsonSerializer
{
ContractResolver = new UnderscoreToCamelCasePropertyResolver(),
};
client.AddHandler("application/json", new NewtonsoftJsonDeserializer(serializer));
client.Authenticator = new HttpBasicAuthenticator(GoCardless.AccountDetails.AppId, GoCardless.AccountDetails.AppSecret);
var response = client.Execute(request);
if (response.StatusCode != HttpStatusCode.OK)
{
throw new ApiException("Unexpected response : " + (int)response.StatusCode + " " + response.StatusCode);
}
return resource;
}
示例12: GetWebhookEvents
/// <summary>
/// Get a listing of all event types that are available for webhooks.
/// </summary>
/// <returns>A list of event types and descriptions</returns>
public List<WebhookEvents> GetWebhookEvents()
{
var request = new RestRequest();
request.Resource = "/{accountId}/webhooks/events";
return Execute<List<WebhookEvents>>(request);
}
示例13: btnCrear_Click
protected void btnCrear_Click(object sender, EventArgs e)
{
if (validarCampos())
{
RestClient client = new RestClient(ConfigurationManager.AppSettings.Get("endpoint"));
RestRequest request = new RestRequest("kpis/", Method.POST);
List<DetalleFormula> formulaCompleta = new List<DetalleFormula>();
for (int i = 0; i < formula.Count; i++)
{
formulaCompleta.Add(new DetalleFormula(i, variables[i], formula[i]));
}
KPI kpiNuevo = new KPI(0, txtDescripcion.Text, ddlFormato.Text, Convert.ToDouble(txtObjetivo.Text), ddlPeriodicidad.Text, new ParametroKPI(Convert.ToInt32(ddlLimiteInf.Text), Convert.ToInt32(ddlLimiteSup.Text)), formulaCompleta);
request.AddJsonBody(kpiNuevo);
var response = client.Execute(request);
formula = new List<string>();
variables = new List<string>();
operador = false;
Response.Redirect("indicadoresKPI.aspx");
}
else
{
//"error"
}
}
示例14: DeleteAllWebhooks
/// <summary>
/// Delete all webhooks registered for an account.
/// </summary>
/// <returns>True if the webhook deleted successfully.</returns>
public bool DeleteAllWebhooks()
{
var request = new RestRequest(Method.DELETE);
request.Resource = "/{accountId}/webhooks";
return Execute<bool>(request);
}
示例15: CheckCredentials
public bool CheckCredentials(string email, string password)
{
var request = new RestRequest("api/User/CheckCredentials?email={email}&password={password}", Method.GET);
request.AddUrlSegment("email", email);
request.AddUrlSegment("password", password);
return client.Execute<bool>(request).Data;
}