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


C# RestClient.Post方法代码示例

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


在下文中一共展示了RestClient.Post方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SignIn

        public RedirectResult SignIn(string login, string password, string appId, 
            string redirectUri, string state)
        {
            var client = new RestClient(SiteConn.AuthWebApiServer);
           

            var signInRequest = new RestRequest("Auth/SignIn");

            signInRequest.AddQueryParameter("login",login);
            signInRequest.AddQueryParameter("password",password);
            signInRequest.AddQueryParameter("appId",appId);
            signInRequest.AddQueryParameter("redirectUri", redirectUri);
            signInRequest.AddQueryParameter("state","666");

            var response = client.Post(signInRequest);
            if (response == null) return new RedirectResult(redirectUri);

            //получаю куки с токеном
            if (response.Cookies != null)
            {
                return new RedirectResult(redirectUri);
            }
            
            return null;
        }
开发者ID:Trigun27,项目名称:rsoi_lab3.FrontEnd,代码行数:25,代码来源:AuthMvcController.cs

示例2: SignIn

        public RedirectResult SignIn(string login, string password, string appId, 
            string redirectUri, string state)
        {
            var client = new RestClient("http://localhost:9999/api/");
            var signInRequest = new RestRequest("Auth/SignIn");

            signInRequest.AddQueryParameter("login",login);
            signInRequest.AddQueryParameter("password",password);
            signInRequest.AddQueryParameter("appId",appId);
            signInRequest.AddQueryParameter("redirectUri", redirectUri);
            signInRequest.AddQueryParameter("state","666");

            var response = client.Post(signInRequest);
            var url = response.ResponseUri.ToString();

            var urlArr = url.Split('?', '=', '&');
            var user = Auth(login, password);
            if (user == null)
                throw new ArgumentException("Неверная пара логин/пароль");

            var app = _appDataReposytory.AppDatas.FirstOrDefault(e => e.Id.ToString() == appId);
            if (app == null)
                throw new Exception("Нет приложения с таким appId");


            _codes.Add(urlArr[2], user.Id);

            //_sessionHelper.CreateNewSession(user, app);

            return new RedirectResult(url);
        }
开发者ID:Trigun27,项目名称:rsoi_lab2,代码行数:31,代码来源:AuthMvcController.cs

示例3: Main

        static void Main(string[] args)
        {
            var appName = string.Empty;
            var hostName = string.Empty;
            var help = false;

            var p = new OptionSet
                {
                    {"app=", v => appName = v},
                    {"host=", v => hostName = v},
                    {"h|?|help", v => help = v != null},
                };
            p.Parse(args);

            if (help || string.IsNullOrWhiteSpace(appName) || string.IsNullOrWhiteSpace(hostName))
            {
                p.WriteOptionDescriptions(Console.Out);
                return;
            }

            var restClient = new RestClient("http://" + hostName + ":9000");
            var request = new RestRequest("/api/v1/install-queue/" + appName, Method.POST) {RequestFormat = DataFormat.Json};
            request.AddBody(new { @null = string.Empty });
            var response = restClient.Post(request);

            if (response.StatusCode == HttpStatusCode.Created)
            {
                Console.WriteLine("'{0}' deployment started remotely on '{1}'.", appName, hostName);
            }
        }
开发者ID:davidwhitney,项目名称:deployd-micro,代码行数:30,代码来源:Program.cs

示例4: Flush

        public void Flush(Workspace workspace)
        {
            ConsoleEx.Info($"Running sink: {this.GetType().Name}");

            var request = new RestRequest(@"api/workspaces", Method.POST);
            request.AddJsonBody(workspace);
            request.RequestFormat = DataFormat.Json;

            var restClient = new RestClient(serviceUri);
            var response = restClient.Post(request);
            if(response.StatusCode == HttpStatusCode.OK)
            {
                ConsoleEx.Ok("Workspace analysis report published.");
                var locationHeader = response.Headers.FirstOrDefault(h=> h.Name == "Location");
                if (locationHeader != null)
                {
                    string workspaceLocation = locationHeader.Value.ToString().ToLower();
                    ConsoleEx.Ok($"Visit {workspaceLocation}");
                }
            }
            else
            {
                ConsoleEx.Error($"Workspace not published to target sink.");
                ConsoleEx.Error($"Status: {response.StatusCode}, Response: {response.Content}");
            }
        }
开发者ID:rdagumampan,项目名称:arnis,代码行数:26,代码来源:WebSink.cs

示例5: Send

        public void Send(OutgoingMessage outgoingMessage)
        {
            var client = new RestClient(TwilioBaseUrl);
            client.Authenticator = new HttpBasicAuthenticator(AccountSid, AuthToken);
            const string sendResource = "/SMS/Messages.json";
            var request = new RestRequest(sendResource, Method.POST);
            request.AddParameter("From", From);
            request.AddParameter("To", outgoingMessage.To);
            request.AddParameter("Body", outgoingMessage.Body);
            var response = client.Post<TwilioResponse>(request);
            if (response.ErrorException != null)
            {
                throw response.ErrorException;
            }            
            if(response.Data.Status!="queued")
            {
                throw new Exception(response.Data.Message);
            }

            _repository.Create(new LoggedOutgoingMessage
                                   {
                                       Body = outgoingMessage.Body,
                                       Sent = SystemDateTime.Now(),
                                       ToNumber = outgoingMessage.To
                                   });
        }
开发者ID:AcklenAvenue,项目名称:AutomatedCaseworker,代码行数:26,代码来源:TwilioMessageSender.cs

示例6: Run

 public IRestResponse Run(Step step, ScenarioContext context)
 {
     var apiPostStep = (ApiPostStep) step;
     var client = new RestClient(apiPostStep.Host);
     var restRequest = BuildRequest(apiPostStep);
     restRequest.AddBody(apiPostStep.Payload);
     return client.Post(restRequest);
 }
开发者ID:AcklenAvenue,项目名称:Pepino,代码行数:8,代码来源:ApiPostStepStrategy.cs

示例7: Shorten

 public string Shorten(string urlToShorten)
 {
     IRestClient client = new RestClient(SHORTENER_API);
     IRestRequest request = new RestRequest(SHORTEN_ENDPOINT);
     request.RequestFormat = DataFormat.Json;
     request.AddBody(new { longUrl = urlToShorten });
     IRestResponse response = client.Post(request);
     dynamic json = response.Content;
     return json.id ?? urlToShorten;
 }
开发者ID:bevacqua,项目名称:Swarm,代码行数:10,代码来源:GoogleUrlShortener.cs

示例8: post

 public static String post(String title, String content)
 {
     RestClient rc = new RestClient("http://app.askform.cn");
     RestRequest request = new RestRequest("{guide}.aspx?Type={type}");
     request.AddUrlSegment("guide", instance.FromGuide);
     request.AddUrlSegment("type", instance.FormType.ToString());
     request.AddParameter("Survey.F77960001-2", title);
     request.AddParameter("Survey.F77960001-3", content);
     request.AddParameter("Survey_duration", "0");
     IRestResponse respone= rc.Post(request);
     return respone.StatusCode.ToString();
 }
开发者ID:htynkn,项目名称:vdh,代码行数:12,代码来源:Askform.cs

示例9: GetAccessToken

        private static AdmAccessToken GetAccessToken(string clientId, string clientSecret)
        {
            const string accessUri = "https://datamarket.accesscontrol.windows.net/v2/OAuth2-13";
            var restClient = new RestClient(accessUri);
            var request = new RestRequest(Method.POST);
            request.AddHeader("Content-Type", "x-www-form-urlencoded");
            request.AddParameter("grant_type", "client_credentials");
            request.AddParameter("client_id", clientId);
            request.AddParameter("client_secret", clientSecret);
            request.AddParameter("scope", "http://api.microsofttranslator.com");

            var token = restClient.Post<AdmAccessToken>(request);

            return token.Data;
        }
开发者ID:thesheps,项目名称:lemonade,代码行数:15,代码来源:BingResourceTranslator.cs

示例10: requestToken

        /// <summary>
        /// Requests a Github API token, given you received a code first, i.e. user allowed that.
        /// 
        /// See OAuth documentation for how to do that.
        /// Your App needs to be registered first.
        /// </summary>
        /// <param name="client_id">your app's client_id</param>
        /// <param name="client_secret">your app's secret</param>
        /// <param name="code">code you got from github</param>
        /// <returns>oauth token if successful, null otherwise</returns>
        public static string requestToken(string client_id, string client_secret, string code)
        {
            // Not on api.github.com
            var client = new RestClient("https://github.com");
            client.UserAgent = "mabako/Git.hub";

            var request = new RestRequest("/login/oauth/access_token");
            request.RequestFormat = DataFormat.Json;
            request.AddParameter("client_id", client_id);
            request.AddParameter("client_secret", client_secret);
            request.AddParameter("code", code);

            var response = client.Post<OAuth2Data>(request);
            if (response.Data != null)
                return response.Data.AccessToken;
            return null;
        }
开发者ID:ArsenShnurkov,项目名称:Git.hub,代码行数:27,代码来源:OAuth2Helper.cs

示例11: PhoneHome

        private void PhoneHome()
        {
            while (true)
            {
                var restClient = new RestClient("http://localhost:9001") {Timeout = 1000};
                var request = new RestRequest("/api/v1/clients/register", Method.POST) {RequestFormat = DataFormat.Json};
                request.AddBody(new { @null = string.Empty });
                restClient.Post(request);

                if (_cancellation.IsCancellationRequested)
                {
                    break;
                }

                Thread.Sleep(new TimeSpan(0,0,0, 30));
            }
        }
开发者ID:davidwhitney,项目名称:deployd-micro,代码行数:17,代码来源:MothershipCommunicator.cs

示例12: send

            public void send(string recipient, string text)
            {
                if (string.IsNullOrEmpty(text) || text.Length > 603)
                {
                    _log.Error("Unable to send sms because text is null or longer than 603 characters.");
                    return;
                }

                if (string.IsNullOrEmpty(recipient) || !_numberValidator.IsMatch(recipient))
                {
                    _log.Error("Unable to send sms because recipient isn't a valid phone number.");
                    return;
                }

                if (string.IsNullOrEmpty(_username) || string.IsNullOrEmpty(_password))
                {
                    _log.Error("Unable to send sms because 'sms.username' or 'sms.password' is not specified.");
                    return;
                }

                var client = new RestClient("https://json.aspsms.com");
                var request = new RestRequest("SendSimpleTextSMS");
                request.AddJsonBody(new
                {
                    UserName = _username,
                    Password = _password,
                    Originator = "Xpressive.H",
                    Recipients = new [] { recipient },
                    MessageText = text
                });

                var response = client.Post(request);

                if (response.StatusCode != HttpStatusCode.OK && response.ErrorMessage != null)
                {
                    if (response.ErrorException != null)
                    {
                        _log.Error("Error when sending SMS: " + response.ErrorMessage, response.ErrorException);
                    }
                    else
                    {
                        _log.Error("Error when sending SMS: " + response.ErrorMessage);
                    }
                }
            }
开发者ID:xpressive-websolutions,项目名称:Xpressive.Home.ProofOfConcept,代码行数:45,代码来源:SmsScriptObjectProvider.cs

示例13: AddMan

        public RedirectToRouteResult AddMan(Manufacturer man)
        {
            var token = _sessionHelper.GetToken();

            if (token == "SessionIsNull")
                return RedirectToAction("GoToErrorForm", "Cpu");

            var clientMan = new RestClient(SiteConn.ManWebApiServer);
            var addMan = new RestRequest($"Man/AddMan", Method.POST)
            {
                RequestFormat = DataFormat.Json
            };

            addMan.AddHeader("Authorization", token);
            addMan.AddHeader("Content-Type", "application/json");

            addMan.AddObject(man);

            var responseMan = clientMan.Post(addMan);

            return RedirectToAction("List", "Man");
        }
开发者ID:Trigun27,项目名称:rsoi_lab3.FrontEnd,代码行数:22,代码来源:ManController.cs

示例14: Register

        //private readonly string serviceUri = "http://localhost:5000";

        public Registration Register(string emailAddress)
        {
            var serviceClient = new RestClient(serviceUri);

            var request = new RestRequest(@"api/accounts", Method.POST);
            request.AddJsonBody(new
            {
                email = emailAddress
            });
            request.RequestFormat = DataFormat.Json;

            var response = serviceClient.Post<Registration>(request);
            if (response.StatusCode == HttpStatusCode.OK)
            {
                return response.Data;
            }
            else
            {
                ConsoleEx.Error($"Registration failed.");
                ConsoleEx.Error($"Status: {response.StatusCode}, Response: {response.Content}");
                return null;
            }
        }
开发者ID:rdagumampan,项目名称:arnis,代码行数:25,代码来源:WebSinkRegistrar.cs

示例15: HttpPost

 public static string HttpPost(this Uri uri, IDictionary<string, string> parameters)
 {
     RestClient client = new RestClient(uri.GetBaseUrl());
     RestRequest request = new RestRequest();
     if (parameters != null)
     {
         foreach (KeyValuePair<string, string> pair in parameters)
         {
             request.AddParameter(pair.Key, pair.Value);
         }
     }
     IRestResponse response = client.Post(request);
     response.CheckResponse();
     return response.Content;
 }
开发者ID:zhang-xiao-ming,项目名称:RestApiClient,代码行数:15,代码来源:UriExtensions.cs


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