本文整理汇总了C#中RestSharp.RestRequest.AddParameter方法的典型用法代码示例。如果您正苦于以下问题:C# RestRequest.AddParameter方法的具体用法?C# RestRequest.AddParameter怎么用?C# RestRequest.AddParameter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RestSharp.RestRequest
的用法示例。
在下文中一共展示了RestRequest.AddParameter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BookIdForIsbn
//Not working.
public Book BookIdForIsbn(String isbn, out Boolean success)
{
try
{
_restClient.BaseUrl = ApiBaseUrl;
_restClient.Authenticator = PublicMethods();
var request = new RestRequest("book/isbn", Method.GET);
request.AddParameter("isbn", isbn);
request.AddParameter("key", _apiKey);
request.AddParameter("format", "xml");
//_restClient.AddHandler();
var response = _restClient.Execute<Book>(request);
if (response.ResponseStatus == ResponseStatus.Error)
{
success = false;
return null;
}
else
{
success = true;
return response.Data;
}
}
catch (Exception ex)
{
success = false;
return null;
}
}
示例2: RegisterCardData
/// <summary>Creates new card registration data.</summary>
/// <param name="cardRegistration">Card registration data object to create.</param>
/// <returns>Card registration object returned from API.</returns>
public CardRegistrationDataDTO RegisterCardData(CardRegistrationDataPostDTO cardRegistrationData)
{
var client = new RestClient(cardRegistrationData.CardRegistrationURL);
var request = new RestRequest(Method.POST);
request.AddParameter(Constants.DATA, cardRegistrationData.PreregistrationData);
request.AddParameter(Constants.ACCESS_KEY_REF, cardRegistrationData.AccessKey);
request.AddParameter(Constants.CARD_NUMBER, cardRegistrationData.CardNumber);
request.AddParameter(Constants.CARD_EXPIRATION_DATE, cardRegistrationData.CardExpirationDate);
request.AddParameter(Constants.CARD_CVX, cardRegistrationData.CardCvx);
var response = client.Execute(request);
var responseString = response.Content;
if (response.StatusCode == HttpStatusCode.OK)
{
var cardRegistrationDataDTO = new CardRegistrationDataDTO
{
RegistrationData = responseString
};
return cardRegistrationDataDTO;
}
else
throw new Exception(responseString);
}
示例3: Search
public IRestResponse<MarketplaceSearchResponse> Search(string query = "", int start = 0, int count = 10)
{
var client = new MarketplaceClient(BaseUrl);
var request = new RestRequest("/", Method.GET);
request.AddHeader("Accept", "*/*");
request.AddHeader("Accept-Enclding", "gzip,deflat,sdch");
request.AddHeader("Cache-Control", "no-cache");
request.AddHeader("HOST", "steamcommunity.com");
request.AddCookie("__ngDebug", "false");
request.AddCookie("Steam_Language", "english");
request.AddCookie("sessionid", "MTE3OTk1OTgyNQ");
request.AddCookie("steamCC_67_167_177_70", "US");
request.AddCookie("__utma", "268881843.805413192.1378770011.1382167972.1382171160.10");
request.AddCookie("__utmb", "268881843.1.10.1382171160");
request.AddCookie("__utmc", "268881843");
request.AddCookie("__utmz", "268881843.1382171160.10.6.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided)");
//request.AddCookie("timezoneOffset", "-14400,0");
//request.Timeout = 5*1000;
request.AddHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36");
request.AddParameter("query", query, ParameterType.GetOrPost);
request.AddParameter("start", start, ParameterType.GetOrPost);
request.AddParameter("count", count, ParameterType.GetOrPost);
var response = client.Get<MarketplaceSearchResponse>(request);
return response;
}
示例4: SendMail
public static string SendMail(string tittel, string tekst, List<Data.MailPerson> personer)
{
foreach (var person in personer)
{
var message = tekst.Replace("[competitionlink]", "alf.apphb.com/Competition/SignUp/" + person.Id.ToString());
message = message.Replace("[betalingslink]", "https://www.deltager.no/participant/arrangement.aspx?id=66098");
message = message.Replace("[navn]", person.Navn);
var client = new RestClient();
client.BaseUrl = "https://api.mailgun.net/v2";
client.Authenticator = new HttpBasicAuthenticator("api", "key-95iv2azanw509luzmo3a7eepdkfy3uu8");
var request = new RestRequest();
request.AddParameter("domain", "app13455.mailgun.org", ParameterType.UrlSegment);
request.Resource = "{domain}/messages";
request.AddParameter("from", "Another Lindyhop Festival <[email protected]>");
request.AddParameter("to", person.Adresse);
request.AddParameter("subject", tittel);
request.AddParameter("text", message);
request.Method = Method.POST;
var response = client.Execute(request);
}
return "Ok.";
}
示例5: PrepareRequest
// Creates and sets up a RestRequest prior to a call.
private RestRequest PrepareRequest(
String path, RestSharp.Method method, Dictionary<String, String> queryParams, String postBody,
Dictionary<String, String> headerParams, Dictionary<String, String> formParams,
Dictionary<String, FileParameter> fileParams, Dictionary<String, String> pathParams)
{
var request = new RestRequest(path, method);
// add path parameter, if any
foreach(var param in pathParams)
request.AddParameter(param.Key, param.Value, ParameterType.UrlSegment);
// add header parameter, if any
foreach(var param in headerParams)
request.AddHeader(param.Key, param.Value);
// add query parameter, if any
foreach(var param in queryParams)
request.AddQueryParameter(param.Key, param.Value);
// add form parameter, if any
foreach(var param in formParams)
request.AddParameter(param.Key, param.Value);
// add file parameter, if any
foreach(var param in fileParams)
request.AddFile(param.Value.Name, param.Value.Writer, param.Value.FileName, param.Value.ContentType);
if (postBody != null) // http body (model) parameter
request.AddParameter("application/json", postBody, ParameterType.RequestBody);
return request;
}
示例6: ExecuteJobRequest
private string ExecuteJobRequest(RestClient client)
{
var req = new RestRequest(@"1/job", Method.POST);
req.AlwaysMultipartFormData = true;
req.AddParameter("apikey", ApiKey);
req.AddParameter("job", JsonConvert.SerializeObject(_batch));
foreach (var v in _files)
{
req.AddFile(v.Key, v.Value);
}
string resp = null;
client.ExecuteAsync(req, response => { resp = response.Content; });
DateTime timeoutTime = DateTime.Now + TimeoutSpan;
while (string.IsNullOrEmpty(resp) && DateTime.Now < timeoutTime)
{
System.Threading.Thread.Sleep(1000);
}
if (resp == null)
{
throw new TimeoutException("Initial job request timed out");
}
return resp;
}
示例7: Login
public static string Login(string login, string password)
{
var request = new RestRequest("rest/user/login", Method.POST);
request.AddParameter("login", login);
request.AddParameter("password", password);
var client = new RestClient();
client.BaseUrl = GetBaseUrl().ToString();
var response = client.Execute(request);
switch (response.StatusCode)
{
case HttpStatusCode.OK:
CookieAuthenticator.RedirectFromLogin(login, response.Cookies);
return null;
case HttpStatusCode.Forbidden:
dynamic x = JsonConvert.DeserializeObject(response.Content);
string error = x.value;
return error;
default:
return string.Format("YouTrack returned {0}: {1}",
(int) response.StatusCode,
response.StatusDescription);
}
}
示例8: Main
static void Main(string[] args)
{
string customerId = "";
string apikey = "";
string address = "address1=2905+premiere+parkway+ste+200&zipcode=30097";
string url = "https://rapid.peachtreedata.com/api/v1/AddressCleanseGeoCode";
string fullurl = url + "?CustomerID=" + customerId + "&APIKEY=" + apikey + "&" + address;
var client = new RestClient(url);
var request = new RestRequest();
request.AddParameter("CustomerID", "XXX999");
request.AddParameter("apikey", "e78f9d79-8710-4753-a099-88c95ea11d0f");
request.AddParameter("Address1", "2905 premiere parkway");
request.AddParameter("ZIPCode", "30097");
request.AddParameter("CompanyName", "peachtree ");
var response = client.Execute <AddressCleanseGeoCodeResponse>(request);
Console.WriteLine("Primary Address: {0}", response.Data.PrimaryAddress);
Console.WriteLine("Secondary Address: {0}", response.Data.SecondaryAddress);
Console.WriteLine("ZIP Code: {0}", response.Data.Zip10);
Console.WriteLine("Latitude: {0}", response.Data.Latitude);
Console.WriteLine("Longitude: {0}", response.Data.Longitude);
Console.WriteLine("Geo Assignment: {0}", response.Data.AssignmentLevel);
Console.WriteLine("Status: {0}", response.Data.StatusMessage);
Console.WriteLine("\n\nPress any key to continue...");
Console.ReadKey();
}
示例9: UploadFile
/// <summary>
/// Uploads a file, if the request fails this overload will delete the note record
/// </summary>
/// <param name="module">Notes</param>
/// <param name="id">Record ID</param>
/// <param name="filePath">Path to file on local disk</param>
/// <param name="deleteOnFailure">Bool: deletes record if upload fails</param>
/// <returns>Bool</returns>
public bool UploadFile(string module, string id, string filePath, bool deleteOnFailure)
{
var request = new RestRequest("{module}/{id}/file/filename", Method.POST);
request.AddUrlSegment("module", module);
request.AddUrlSegment("id", id);
request.AddParameter("format", "sugar-html-json");
request.AddParameter("delete_if_fails", deleteOnFailure);
if (deleteOnFailure)
{
request.AddParameter("oauth_token", Token);
}
if (!File.Exists(filePath))
{
//@todo create a SugarFileException class
throw new SugarException("Can not locate file path. Path attempted = " + filePath);
}
request.AddFile("filename", filePath);//?
FileUploadResponse response = Execute<FileUploadResponse>(request);
return ! string.IsNullOrEmpty(response.filename.name);
}
示例10: SignIn
private void SignIn(String username, String password)
{
bool isValid = this.ValidateForm(username, password);
if (isValid)
{
SignInButton.IsEnabled = false;
var client = new RestClient("https://securebox.io/");
var request = new RestRequest("api-token-auth/", Method.POST);
request.AddParameter("username", username); // adds to POST or URL querystring based on Method
request.AddParameter("password", password); // adds to POST or URL querystring based on Method
IRestResponse<MyToken> response = client.Execute<MyToken>(request);
try
{
var token = response.Data.Token;
if (token != null)
{
this.RedirectToMainForm();
}
else
{
ValidationMessage.Content = "Invalid login";
SignInButton.IsEnabled = true;
}
//MessageBox.Show(token.ToString());
//System.Windows.MessageBox.Show(token.ToString());
}
catch
{
var content = response;
System.Windows.MessageBox.Show("Error");
}
}
}
示例11: GetToken_Click
private void GetToken_Click(object sender, RoutedEventArgs e)
{
var client = new RestClient("https://api.home.nest.com/oauth2/access_token");
var request = new RestRequest(Method.POST);
request.AddParameter("client_id", TextNestClientId.Text);
request.AddParameter("code", TextNestPin.Text);
request.AddParameter("client_secret", PwNestSecret.Password);
request.AddParameter("grant_type", "authorization_code");
var response = client.Execute(request);
JsonDeserializer deserializer = new JsonDeserializer();
var json = deserializer.Deserialize<Dictionary<string, string>>(response);
if (json.ContainsKey("access_token"))
{
TextNestAccessToken.Text = json["access_token"];
return;
}
if (json.ContainsKey("message"))
{
TextNestAccessToken.Text = json["message"];
return;
}
if (json.ContainsKey("error_description"))
{
TextNestAccessToken.Text = json["error_description"];
return;
}
}
示例12:
void IObjectValidation.AddParametersToRequest(RestRequest request)
{
request.AddParameter("bank_account[currency]", Currency);
request.AddParameter("bank_account[country]", Country);
request.AddParameter("bank_account[routing_number]", RoutingNumber);
request.AddParameter("bank_account[account_number]", AccountNumber);
}
示例13: GetTicket
public IRestRequest GetTicket(string apiKey)
{
var restRequest = new RestRequest("1.0/rest");
restRequest.AddParameter("action", "get_ticket");
restRequest.AddParameter("api_key", apiKey);
return restRequest;
}
示例14: SendResetMessage
//TO:DO: Error Handling
/// <summary>
/// Handles the Sending of the reset password email.
/// </summary>
/// <param name="user">UserReset Model</param>
/// <returns>client.Execute(request)</returns>
public async Task<IRestResponse> SendResetMessage()
{
string subjectParam = "Reset Password";
RestClient client = new RestClient();
client.BaseUrl = "https://api.mailgun.net/v2";
client.Authenticator =
new HttpBasicAuthenticator("api",
mailGunApiKey);
RestRequest request = new RestRequest();
request.AddParameter("domain",
mailGunDomain, ParameterType.UrlSegment);
request.Resource = "{domain}/messages";
request.AddParameter("from", mailGunEmail);
request.AddParameter("to", EmailAddress);
request.AddParameter("subject", subjectParam);
request.AddParameter("html", await ResetMessage());
//upload token to parse
await SendKey();
request.Method = Method.POST;
return client.Execute(request);
}
示例15: GetBaseRestRequest
private RestRequest GetBaseRestRequest(string requestUri)
{
var request = new RestRequest(requestUri, Method.GET);
request.AddParameter("api_key", _apiKey);
request.AddParameter("pretty", 1);
return request;
}