本文整理汇总了C#中RestSharp.RestRequest.AddObject方法的典型用法代码示例。如果您正苦于以下问题:C# RestRequest.AddObject方法的具体用法?C# RestRequest.AddObject怎么用?C# RestRequest.AddObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RestSharp.RestRequest
的用法示例。
在下文中一共展示了RestRequest.AddObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
var cl = new RestClient("http://demo.vivapayments.com/");
//var cl = new RestClient("https://www.vivapayments.com/"); // production URL
var req = new RestRequest("api/orders", Method.POST);
req.AddObject(new OrderOptions()
{
Amount = 100 // Amount is in cents
});
string MerchantId = Guid.Parse("1c204c59-9890-499c-bf5d-31e80dcdbdfd").ToString(); // the merchant id is found in the self-care environment (developers menu)
string Password = "a123456"; // the password is set in the self-care environment (developers menu)
cl.Authenticator = new HttpBasicAuthenticator(MerchantId, Password);
// Do the post
var res = cl.Execute<OrderResult>(req);
// once the order code is successfully created, redirect to payment form to complete the payment
if (res.Data.ErrorCode == 0)
{
Response.Redirect(this.vivaPaymentFormURL + res.Data.OrderCode.ToString());
}
}
示例2: GetBoxScores
private static void GetBoxScores(string authToken)
{
var start = 0;
while (true)
{
var request = new RestRequest("/user/teams/football/boxScores");
request.AddHeader("Authorization", authToken);
request.AddObject(new GetUserTeamsFootballBoxScores { Offset = start, Count = PageSize });
var response = _restClient.Execute<FootballBoxScoresResponse>(request);
if (response.StatusCode == HttpStatusCode.OK)
{
foreach (var boxScore in response.Data.BoxScores)
{
var text = boxScore.AwayTeamName + " @ " + boxScore.HomeTeamName + " - " + boxScore.StatusDisplay;
if (boxScore.Status == Status.Complete) {
text = text + " (" + boxScore.AwayTeamAcronym + " " + boxScore.AwayScore + ", " + boxScore.HomeTeamAcronym + " " + boxScore.HomeScore + ")";
}
Console.WriteLine(text);
}
if (response.Data.BoxScores.Count == 0 || response.Data.BoxScores.Count() == response.Data.TotalCount)
break;
start += response.Data.BoxScores.Count;
}
else if (response.StatusCode == HttpStatusCode.Unauthorized)
throw new Exception("Auth token expired. Reauthenticate");
else
throw new Exception(string.Format("Error getting box scores: {0}", response.StatusCode));
}
}
示例3: Create
public ActionResult Create(SetTagDTO collection)
{
if (!Session["Role"].Equals("Admin"))
{
return RedirectToAction("Index", "Home");
}
var request = new RestRequest("api/Tags/", Method.POST);
var apiKey = Session["ApiKey"];
var UserId = Session["UserId"];
request.AddHeader("xcmps383authenticationkey", apiKey.ToString());
request.AddHeader("xcmps383authenticationid", UserId.ToString());
request.AddObject(collection);
var queryResult = client.Execute(request);
statusCodeCheck(queryResult);
if (queryResult.StatusCode != HttpStatusCode.Created)
{
return View();
}
else if (queryResult.StatusCode == HttpStatusCode.Forbidden)
{
return RedirectToAction("Login", "User");
}
return RedirectToAction("Index");
}
示例4: AddUser
public ActionResult AddUser(User user)
{
var client = new RestClient(ServerBaseUrl + "UserRoles/AddUser");
RestRequest request = new RestRequest(Method.POST);
request.AddObject(user);
int intt= client.Execute<int>(request).Data;
return RedirectToAction("AllUsers");
}
示例5: Save
public static bool Save(BoredModel model)
{
var client = new RestClient(BaseUrl);
var request = new RestRequest("save/{ver}", Method.POST);
request.AddUrlSegment("ver", Ver);
request.AddObject(model);
IRestResponse response = client.Execute(request);
return response.StatusCode == System.Net.HttpStatusCode.OK;
}
示例6: UpdateSharing
//public Sharing CreateSharing(int projectId, Sharing sharing)
//{
// var request = new RestRequest();
// request.Resource = string.Format("projects/{0}/sharings.xml", projectId);
// request.Method = Method.POST;
// request.AddObject(sharing);
// return Execute<Sharing>(request);
//}
public Sharing UpdateSharing(Sharing sharing)
{
var request = new RestRequest();
request.Resource = string.Format("projects/{0}/sharings/{1}.xml", sharing.Project.Id, sharing.Id);
request.Method = Method.PUT;
request.AddObject(sharing);
return Execute<Sharing>(request);
}
示例7: CreateProject
/// <summary>
/// Using the API, you can create a new project in your account.
/// </summary>
/// <param name="project"></param>
/// <returns></returns>
public Project CreateProject(Project project)
{
var request = new RestRequest();
request.Resource = "projects.xml";
request.Method = Method.POST;
request.AddObject(project);
return Execute<Project>(request);
}
示例8: Authenticate
private static string Authenticate()
{
var request = new RestRequest("/authenticate", Method.POST);
request.AddObject(new Authenticate { Username = Username, Password = Password });
var response = _restClient.Execute<AuthenticateResponse>(request);
if (response.StatusCode == HttpStatusCode.OK)
return response.Data.AuthToken;
else if (response.StatusCode == HttpStatusCode.Unauthorized)
throw new Exception("Invalid username/password");
else
throw new Exception(string.Format("Error calling authenticate: {0}", response.StatusCode));
}
示例9: PostMessage
public void PostMessage(SlackMessage message, params SlackAttachment[] attachments)
{
var request = new RestRequest("chat.postMessage", Method.POST) {RequestFormat = DataFormat.Json};
request.AddHeader("Content-Type", "application/json");
request.AddObject(message);
if (attachments.Any())
{
request.AddParameter("attachments", JsonConvert.SerializeObject(attachments));
}
_restClient.ExecuteAsync(request, response => Trace.TraceInformation(string.Format("Slack response: {0}", response.Content)));
}
示例10: Create
public Order Create(CreateOrderRequest o)
{
var request = new RestRequest
{
Resource = _orderPath,
Method = Method.POST,
};
request.RequestFormat = DataFormat.Json;
request.AddObject(o);
var response = Client.ExecuteWithErrorCheck<Order>(request);
return response.Data;
}
示例11: generarTipoKpi
public void generarTipoKpi()
{
string[] tipoKpi = { "Ventas", "Prospectos", "Vendedores" };
RestClient client = new RestClient(ConfigurationManager.AppSettings["endpoint"]);
RestRequest request = new RestRequest("tipo_kpi", Method.POST);
request.RequestFormat = DataFormat.Json;
for (int i = 0; i < tipoKpi.Length; i++)
{
TipoKpi nuevoTipo = new TipoKpi(tipoKpi[i]);
request.AddObject(nuevoTipo);
var response = client.Execute(request) as RestResponse;
}
}
示例12: CreateWithData
public OrderItem CreateWithData(long orderId,OrderItemRequest orderItem, Stream fileData)
{
var request = new RestRequest
{
Resource = _orderItemPath,
Method = Method.POST
};
request.AddParameter("orderId", orderId, ParameterType.UrlSegment);
request.AddObject(orderItem, "Type", "Url", "Copies", "Sizing", "PriceToUser", "Md5Hash");
byte[] allData = new byte[fileData.Length];
fileData.Read(allData,0,allData.Length);
request.AddFile("image",allData,"image.jpg");
var response = Client.ExecuteWithErrorCheck<OrderItem>(request);
fileData.Dispose();
return response.Data;
}
示例13: CreateOrder
public IRestResponse<OrderResult> CreateOrder(long amount, string sourceCode)
{
var cl = new RestClient(_BaseApiUrl);
cl.Authenticator = new HttpBasicAuthenticator(
_MerchantId.ToString(),
_ApiKey);
var req = new RestRequest(_PaymentsCreateOrderUrl, Method.POST);
req.AddObject(new
{
Amount = amount, // Amount is in cents
SourceCode = sourceCode
});
return cl.Execute<OrderResult>(req);
}
示例14: TestParameters
public void TestParameters()
{
var client = new RestClient("http://example.com");
var request = new RestRequest("resource/{id}", Method.POST);
// adds to POST or URL querystring based on Method
request.AddParameter("name", "value");
// replaces matching token in request.Resource
request.AddUrlSegment("id", "123");
// add parameters for all properties on an object
request.AddObject(new MyInt{myInt = 42});
// add files to upload (works with compatible verbs)
// may throw a FileNotFoundException
request.AddFile("name", "path");
}
示例15: UpdateToDo
public void UpdateToDo(Models.ToDo toDo, Action<bool> callbackAction)
{
var client = new RestClient("http://localhost:8888/ToDoServices/api/ToDo/Update");
var request = new RestRequest(Method.POST);
request.AddObject(toDo);
client.ExecuteAsync(request, (response, handle) =>
{
if (response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.NoContent)
{
DispatcherHelper.CheckBeginInvokeOnUI(() => callbackAction.Invoke(true));
}
else
{
callbackAction.Invoke(false);
}
});
}