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


C# RestClient.Execute方法代码示例

本文整理汇总了C#中RestSharp.RestClient.Execute方法的典型用法代码示例。如果您正苦于以下问题:C# RestClient.Execute方法的具体用法?C# RestClient.Execute怎么用?C# RestClient.Execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RestSharp.RestClient的用法示例。


在下文中一共展示了RestClient.Execute方法的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;
        }
开发者ID:PoojaDhingra,项目名称:ArchivalServicesRepo,代码行数:31,代码来源:WebService2.asmx.cs

示例2: CrudTest

        public void CrudTest()
        {
            var bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
            var filename = "something.dummy";
            var mimetype = "application/octet-stream";
            var restClient = new RestClient(baseFileserverUrl);
            var post = new RestRequest(Method.POST);
            post.AddFileBytes(filename, bytes, filename, mimetype);
            var postRes = restClient.Execute(post);
            LogRequest(restClient, post, postRes, 0);

            Assert.AreEqual(ResponseStatus.Completed, postRes.ResponseStatus);
            Assert.AreEqual(HttpStatusCode.Created, postRes.StatusCode);
            var location = postRes.Headers.First(e => e.Name.Equals("Location")).Value.ToString();
            Assert.IsNotNull(location);

            var uri = new Uri(location);
            var filestorageClient = new RestClient(uri);
            var get = new RestRequest(Method.GET);
            var gerRes = filestorageClient.Execute(get);
            Assert.AreEqual(ResponseStatus.Completed, gerRes.ResponseStatus);
            Assert.AreEqual(HttpStatusCode.OK, gerRes.StatusCode);
            Assert.AreEqual(10, gerRes.RawBytes.Length);
            Assert.AreEqual(mimetype, gerRes.ContentType);

            var del = new RestRequest(Method.DELETE);
            var delRes = filestorageClient.Execute(del);
            Assert.AreEqual(ResponseStatus.Completed, delRes.ResponseStatus);
            Assert.AreEqual(HttpStatusCode.NoContent, delRes.StatusCode);
        }
开发者ID:CactusSoft,项目名称:Cactus.Fileserver,代码行数:30,代码来源:CrudIntegrationTest.cs

示例3: CreateInstance

        public void CreateInstance(string code)
        {
            var client = new RestClient("https://console.cloud-elements.com/elements/api-v2");
            var dropbox = "/elements/dropbox/instances";

            var json = @"{
             ""element"": {
               ""key"": ""dropbox""
             },
             ""providerData"": {
               ""code"": """ + code +  @"""
             },
             ""configuration"": {
               ""oauth.callback.url"": ""http://localhost:40669/dropbox"",
               ""oauth.api.key"": ""oaivbq19cgkoia8"",
               ""oauth.api.secret"": ""t6c5spexx0g5fuk"",
               ""document.tagging"": false
             },
             ""tags"": [
               ""test""
             ],
             ""name"": ""hui-test-" + new Random().Next() + @"""
            }";
            var createInstance = new RestRequest(dropbox, Method.POST) { RequestFormat = DataFormat.Json };
            createInstance.AddHeader("Authorization", "User kiJp+N8I12IAynsqCqq4I7M/XuwS6aUSJR4hLPLYCI8=, Organization 1eaea1a56a443c25f529ca678c4cd66b");

            //createInstance.AddParameter("elementInstance",json,  "application/json",  ParameterType.RequestBody);
            createInstance.AddParameter("application/json", json, ParameterType.RequestBody);
            //            createInstance.AddBody(json);

            var restResponse = client.Execute(createInstance);
            var restfulResponse = new RestfulResponse(restResponse, dropbox);
        }
开发者ID:Rallyteam,项目名称:Geoffrey,代码行数:33,代码来源:DropboxService.cs

示例4: callPhone

        static void callPhone(string phonenumber, string message)
        {
            ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(
                delegate
                {
                    return true;
                });

            var client = new RestClient("https://api.shoutpoint.com");
            var request = new RestRequest("v0/Dials/Connect", Method.POST);
            request.AddHeader("x-api-key", "SncRoqW8Lf4B4xA0nv5MH9tzKHnPfraA");
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", "{\"call\":{\"no\":" + phonenumber + ",\"caller_id_no\":\"17607183780\"}}", ParameterType.RequestBody);//16024784411
            var responce = client.Execute(request);//19492465047
            Console.WriteLine(responce);
            callobj test = JsonConvert.DeserializeObject<callobj>(responce.Content);
            var request2 = new RestRequest("v0/LiveCalls/" + test.call.id + "/Actions/HangUp", Method.POST);
            request2.AddHeader("x-api-key", "SncRoqW8Lf4B4xA0nv5MH9tzKHnPfraA");
            request2.AddHeader("Content-Type", "application/json");
            request2.AddParameter("application/json", "{\"message\":[\"" + message + "\"]}", ParameterType.RequestBody);
            var responce2 = client.Execute(request2);
            //var endcall= new RestRequest("v0/Dials/Connect", Method.POST);
            //endcall.AddHeader("x-api-key", "SncRoqW8Lf4B4xA0nv5MH9tzKHnPfraA");
            //endcall.AddHeader("Content-Type", "application/json");
        }
开发者ID:OfriHarlev,项目名称:callender-backend,代码行数:25,代码来源:Program.cs

示例5: Main

        static void Main(string[] args)
        {
            while (true) {
            string choice;
            string id;
            int status;

            var client = new RestClient("http://192.168.0.3:1337/auto/api/v1.0/");
            var request = new RestRequest("relays", Method.GET);
            request.OnBeforeDeserialization = resp => { resp.ContentType = "application/json"; };

            var response = client.Execute<Relay>(request);
            var RelayCollection = client.Execute<RelayCollection>(request);

            Console.WriteLine(RelayCollection.Content);
            Console.WriteLine("What id do you want to change?");
            id = Console.ReadLine();
            Console.WriteLine("We will change id:{0}\nwhat do you want to do?\n0 = off 1 = on", id);
            choice = Console.ReadLine();
            if(choice == "1")
            {
                status = 1;
            }
            else
            {
                status = 0;
            }

            var putRequest = new RestRequest("relays/" + id, Method.PUT);
            putRequest.AddJsonBody(new { status = status });
            client.Execute(putRequest);

            }
        }
开发者ID:AlexanderMalmstrom,项目名称:Room-Automation-Win32Client,代码行数:34,代码来源:Program.cs

示例6: Index

        //
        // GET: /Home/
        public ActionResult Index()
        {
            var restClient = new RestClient("https://api.scrumwise.com/service/api/v1");
            restClient.Authenticator = new HttpBasicAuthenticator("[email protected]", "F7C66791D5181976523B27F8496D2D0D8AEF0DE03F6AA3A1557FD06BEA9ACFA5");
            var request = new RestRequest("getData");

            request.AddParameter("includeProperties", "Project.backlogItems,BacklogItem.tasks, Data.persons, Project.sprints, Task.timeEntries");
            var response = restClient.Execute<ReturnData>(request);
            var viewRespinse = restClient.Execute(request);

            var sprints = response.Data.Result.Projects.SelectMany(x => x.Sprints).ToList();

            foreach (var sprint in sprints)
            {
                sprint.BacklogItems =
                    response.Data.Result.Projects.SelectMany(x => x.BacklogItems)
                        .Where(x => x.SprintID == sprint.Id)
                        .ToList();
            }

            var vm = new HomepageViewModel
                     {
                         Raw = viewRespinse.Content,
                         Persons =  response.Data.Result.Persons,
                         Sprints = sprints

                     };

            return View("Index", vm);
        }
开发者ID:JamieDixon,项目名称:ScrumwiseReporting,代码行数:32,代码来源:HomeController.cs

示例7: btnGuardar_Click

 protected void btnGuardar_Click(object sender, EventArgs e)
 {
     Template template = new Template();
     template.nombre = txtNombre.Text;
     template.descripcion = txtDescripcion.Value;
     char[] splits = { ',', ' ' };
     string[] ids = HiddenFieldPreguntas.Value.Split(splits);
     foreach (string id in ids)
     {
         if (!id.Equals("")) template.preguntas.Add(new Question(Convert.ToInt32(id)));
     }
     RestClient client = new RestClient(ConfigurationManager.AppSettings["endpoint"]);
     if (Session["IdTemplateEdit"] == null)
     {//POST
         RestRequest request = new RestRequest("Templates", Method.POST);
         request.RequestFormat = DataFormat.Json;
         request.AddBody(template);
         var response = client.Execute(request) as RestResponse;
         if (response.StatusCode.Equals(System.Net.HttpStatusCode.Created)) Response.Redirect("List.aspx");
     }
     else
     {//UPDATE
         RestRequest request = new RestRequest("Templates/" + Session["IdTemplateEdit"].ToString(), Method.PUT);
         template.id_plantilla = Convert.ToInt32(Session["IdTemplateEdit"].ToString());
         request.RequestFormat = DataFormat.Json;
         request.AddBody(template);
         var response = client.Execute(request) as RestResponse;
         if (response.StatusCode.Equals(System.Net.HttpStatusCode.NoContent)) Response.Redirect("List.aspx");
     }
 }
开发者ID:AlejandroBermudezVargas,项目名称:CenfotecSystem---Web,代码行数:30,代码来源:create.aspx.cs

示例8: Can_Authenticate_With_OAuth

        public void Can_Authenticate_With_OAuth()
        {
            const string consumerKey = "HEGlGLuqfR1Aa8CwJNB0sw";
            const string consumerSecret = "D4UC98WMZbPaLztm47b7TwktQBiPhqpqJUd99hPhqw";

            var baseUrl = "http://api.twitter.com";
            var client = new RestClient(baseUrl);
            client.Authenticator = OAuth1Authenticator.ForRequestToken(consumerKey, consumerSecret);
            // Token anfragen für Authorisierung
            var request = new RestRequest("oauth/request_token", Method.POST);
            var response = client.Execute(request);

            Assert.IsNotNull(response);
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);

            var qs = HttpUtility.ParseQueryString(response.Content);
            var oauth_token = qs["oauth_token"];
            var oauth_token_secret = qs["oauth_token_secret"];
            Assert.IsNotNull(oauth_token);
            Assert.IsNotNull(oauth_token_secret);

            // Authorisierung starten
            request = new RestRequest("oauth/authorize");
            request.AddParameter("oauth_token", oauth_token);
            var url = client.BuildUri(request).ToString();
            Process.Start(url);

            // mit Authorisierungs-PIN ein Zugriffs-Token anfordern
            var verifier = "8083248"; // <-- Breakpoint here (set verifier in debugger)
            request = new RestRequest("oauth/access_token", Method.POST);
            client.Authenticator = OAuth1Authenticator.ForAccessToken(
                consumerKey, consumerSecret, oauth_token, oauth_token_secret, verifier
                );
            response = client.Execute(request);

            Assert.IsNotNull(response);
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);

            qs = HttpUtility.ParseQueryString(response.Content);
            oauth_token = qs["oauth_token"];
            oauth_token_secret = qs["oauth_token_secret"];
            Assert.IsNotNull(oauth_token);
            Assert.IsNotNull(oauth_token_secret);

            request = new RestRequest("1.1/statuses/user_timeline.json");
            request.AddParameter("count", 30);
            client.Authenticator = OAuth1Authenticator.ForProtectedResource(
                consumerKey, consumerSecret, oauth_token, oauth_token_secret
                );

            var typedResponse = client.Execute<List<Tweet>>(request);
            var tweets = typedResponse.Data;

            Assert.IsNotNull(response);
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);

            Assert.IsNotNull(tweets);
            Assert.IsTrue(tweets.Count > 0);
        }
开发者ID:Gope,项目名称:DDC_SampleCode,代码行数:59,代码来源:RestSharpSamples.cs

示例9: OnLogInButtonClicked

        public Boolean OnLogInButtonClicked(string email, string password)
        {
            var hud = DependencyService.Get<IHud> ();
            hud.Show ("Verifying Credentials");

            var client = new RestClient("http://dev.envocsupport.com/GameStore2/");
            var request = new RestRequest("api/ApiKey?email=" + email + "&password=" + password, Method.GET);

            request.OnBeforeDeserialization = resp => { resp.ContentType = "application/json"; };

            IRestResponse queryResult = client.Execute(request);

            if (queryResult.StatusCode == HttpStatusCode.OK)
            {
                RestSharp.Deserializers.JsonDeserializer deserial = new JsonDeserializer();
                var x = deserial.Deserialize<UserApiKey>(queryResult);

                Application.Current.Properties["ApiKey"] = x.ApiKey;
                Application.Current.Properties ["UserId"] = x.UserId;

                //Console.WriteLine ("first" + queryResult.Content);
            //				Console.WriteLine ("key:"+x.ApiKey);

                // next request for User
                request = new RestRequest ("api/Users/"+x.UserId,Method.GET);

                var ApiKey = Application.Current.Properties ["ApiKey"];
                var UserId = Application.Current.Properties ["UserId"];

                request.AddHeader ("xcmps383authenticationkey",ApiKey.ToString ());
                request.AddHeader ("xcmps383authenticationid",UserId.ToString ());
                queryResult = client.Execute (request);

                User user = new User ();

                statusCodeCheck (queryResult);

                if (queryResult.StatusCode == HttpStatusCode.OK) {
                    user = deserial.Deserialize<User>(queryResult);
                }

                Application.Current.Properties ["FirstName"] = user.FirstName;

            //				Console.WriteLine (Application.Current.Properties ["UserId"]);
                //Console.WriteLine ("here" + queryResult.Content);

                loginStatus = true;
                return loginStatus ;
            }
            else
            {
                loginStatus = false;
                return loginStatus;

            }
        }
开发者ID:camotts,项目名称:383-Admin-Portal-Mobile-App,代码行数:56,代码来源:UserRepository.cs

示例10: Index

        public ActionResult Index()
        {
            var client = new RestClient("https://openapi.etsy.com/v2/listings/active/");

            var request = new RestRequest(Method.GET);
            request.AddParameter("api_key", ConfigurationManager.AppSettings["MyEtsyKey"]);
            request.AddParameter("includes", "MainImage");
            var results2 = Json(client.Execute(request));

            RestResponse<Results> results = (RestResponse<Results>)client.Execute<Results>(request);
            //    results.Data.results[0].image_id;
            return View(results.Data.results);
        }
开发者ID:brgoza,项目名称:TIY-API-Homework,代码行数:13,代码来源:HomeController.cs

示例11: Get

 public IRestResponse Get(string email)
 {
     RestClient client = new RestClient();
     client.BaseUrl = new Uri("https://api.mailgun.net/v3");
     client.Authenticator =
             new HttpBasicAuthenticator("api",
                                        "pubkey-4589ea7c99231f892c2304bcb754c08c");
     RestRequest request = new RestRequest();
     request.Resource = "/address/validate";
     request.AddParameter("address", email);
     var testVar = client.Execute(request);
     return client.Execute(request);
 }
开发者ID:tcMichaelson,项目名称:famiLYNX,代码行数:13,代码来源:ValidateEmailController.cs

示例12: GetOrder_Test

        public void GetOrder_Test()
        {
            var client = new RestClient("http://localhost:8082/");

            var request = new RestRequest("Api/OrderApi/GetOrder", Method.GET);

            IRestResponse response = client.Execute(request);

            var content = response.Content;

            var order = client.Execute<GetOrderListResponse>(request);

            Assert.AreEqual(128, order.Data.OrderList.Count());
        }
开发者ID:aburok,项目名称:NorthwindStore,代码行数:14,代码来源:OrderApiAcceptanceTests.cs

示例13: Main

        static void Main(string[] args)
        {
            var client = new RestClient("http://localhost:37328/api/");

            var request = new RestRequest("students/{id}", Method.GET);
            request.AddUrlSegment("id", "5");

            var response = client.Execute(request);

            Console.WriteLine(response.Content);

            var serializedResponse = client.Execute<Student>(request);
            Console.WriteLine(serializedResponse.Data);
        }
开发者ID:nok32,项目名称:Web-Services-and-Cloud,代码行数:14,代码来源:Program.cs

示例14: Main

        //public static object msg;
        //private static IRestRequest request;
        static void Main(string[] args)
        {
            while (true)
            {
                Console.WriteLine(" Welcome to Slacker");
                Console.WriteLine(" Would you like to Submit a post or Read a post?");
                Console.WriteLine(" type Submit or Read");
                //Console.ReadLine();

                var client = new RestClient("http://localhost:51500/");

                Message msg = new Message();
                if (Console.ReadLine() == "Submit")
                {

                    Console.WriteLine("please enter UserName");
                    msg.UserName = Console.ReadLine();
                    Console.WriteLine("please enter Text");
                    msg.Text = Console.ReadLine();
                    msg.DatePosted = DateTime.Now;
                    var request = new RestRequest("api/messages/", Method.POST)
                    { RequestFormat = DataFormat.Json };
                    request.AddJsonBody(msg);
                    var response = client.Execute<Message>(request);
                    break;
                }

                else if (Console.ReadLine() == "Read")
                {

                   // var response = client.Execute<Message>(request);
                    request = new RestRequest("api/messages", Method.GET);
                    var messages = client.Execute<List<Message>>(request).Data;
                    messages.ForEach(x => Console.WriteLine(x));
                    //foreach (var x in messages)
                    //{

                    //    Console.WriteLine(x.UserName);
                    //    Console.WriteLine(x.Text);
                    //    Console.WriteLine(x.DatePosted);
                    //    Console.ReadLine();
                    //}
                }
                Console.ReadLine();

                Console.Clear();
                //
            }
        }
开发者ID:Joshuahill84,项目名称:Week3Lab,代码行数:51,代码来源:Program.cs

示例15: getAllDiem

        public static string getAllDiem(string id)
        {
            const string baseUrl = @"http://thongtindaotao.sgu.edu.vn";

            CookieContainer _cookieJar = new CookieContainer();

            var client = new RestClient(baseUrl);
            var request = new RestRequest("/Default.aspx")
            {
                AlwaysMultipartFormData = true,
                Method = Method.GET,
            };

            request.AddParameter("page", "xemdiemthi");
            request.AddParameter("id", id);

            IRestResponse response = client.Execute(request);
            string content = response.Content;
            // get view state
            HtmlDocument document = new HtmlDocument();
            document.LoadHtml(content);
            HtmlNode node = document.DocumentNode.SelectSingleNode("//*[@id='__VIEWSTATE']");
            string viewState = node.Attributes["value"].Value;

            //get cookie
            var sessionCookie = response.Cookies.SingleOrDefault(x => x.Name == "ASP.NET_SessionId");
            if (sessionCookie != null)
            {
                _cookieJar.Add(new Cookie(sessionCookie.Name, sessionCookie.Value, sessionCookie.Path, sessionCookie.Domain));
            }

            request = new RestRequest("/Default.aspx")
            {
                AlwaysMultipartFormData = true,
                Method = Method.POST,
            };

            request.AddParameter("page", "xemdiemthi", ParameterType.QueryString);
            request.AddParameter("id", id, ParameterType.QueryString);
            request.AddParameter("__EVENTTARGET", "ctl00$ContentPlaceHolder1$ctl00$lnkChangeview2", ParameterType.GetOrPost);
            request.AddParameter("__VIEWSTATE", viewState, ParameterType.GetOrPost);

            client.CookieContainer = _cookieJar;

            response = client.Execute(request);
            content = response.Content;

            return content;
        }
开发者ID:tienbui123,项目名称:Service,代码行数:49,代码来源:GetHTML.cs


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