当前位置: 首页>>代码示例>>C#>>正文


C# RestRequest.AddObject方法代码示例

本文整理汇总了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());
        }
    }
开发者ID:pikos-apikos,项目名称:API,代码行数:27,代码来源:CSharp.aspx.cs

示例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));
     }
 }
开发者ID:playon,项目名称:ds-hsgc-api-samples,代码行数:29,代码来源:Program.cs

示例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");
        }
开发者ID:camotts,项目名称:383-Admin-Portal-Mobile-App,代码行数:27,代码来源:TagController.cs

示例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");
 }
开发者ID:hsloki,项目名称:HG,代码行数:8,代码来源:UserRolesController.cs

示例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;
 }
开发者ID:xxy1991,项目名称:cozy,代码行数:9,代码来源:BoredApi.cs

示例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);
        }
开发者ID:ej4,项目名称:Wistia-Wrapper,代码行数:17,代码来源:Sharings.cs

示例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);
        }
开发者ID:ej4,项目名称:Wistia-Wrapper,代码行数:14,代码来源:Projects.cs

示例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));
 }
开发者ID:playon,项目名称:ds-hsgc-api-samples,代码行数:12,代码来源:Program.cs

示例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)));
        }
开发者ID:ryanfreeth,项目名称:LogglySlacker,代码行数:14,代码来源:SlackClient.cs

示例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;
        }
开发者ID:tomgallard,项目名称:pwinty-dotnet,代码行数:14,代码来源:OrderResource.cs

示例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;
            }
        }
开发者ID:AlejandroBermudezVargas,项目名称:CenfotecSystem---Web,代码行数:14,代码来源:KpiVentas.aspx.cs

示例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;
        }
开发者ID:tomgallard,项目名称:pwinty-dotnet,代码行数:17,代码来源:OrderItemResource.cs

示例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);
        }
开发者ID:pikos-apikos,项目名称:API,代码行数:17,代码来源:ApiClient.cs

示例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"); 
		}
开发者ID:Timothep,项目名称:MarathonWOShoes,代码行数:18,代码来源:RestSharp.cs

示例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);
                }
            });
        }
开发者ID:cehager,项目名称:Pluralsight.KnockoutForXaml,代码行数:19,代码来源:ToDoClient.cs


注:本文中的RestSharp.RestRequest.AddObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。