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


C# RestClient.AddParameter方法代码示例

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


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

示例1: UploadString

        /// <summary>
        /// 上传数据
        /// </summary>
        /// <param name="url"></param>
        /// <param name="service"></param>
        /// <param name="queries"></param>
        /// <param name="action"></param>
        /// <param name="failed"></param>
        protected void UploadString(string url
            , IDictionary<string, string> queries
            , Action<RestResponse, object> action
            , Action<Exception> failed
            , object userState)
        {
            bool httpResult = HttpWebRequest.RegisterPrefix("http://", WebRequestCreator.ClientHttp);
            RestClient client = new RestClient();
            client.Method = WebMethod.Post;
            queries.ToList().ForEach(o => client.AddParameter(o.Key, o.Value));
            client.AddHeader("X-Requested-With", "xmlhttp");

            client.Authority = url;
            RestRequest restRequest = new RestRequest();
            CookieContainer cookieContainer = null;
            if (IsolatedStorageSettings.ApplicationSettings.Contains("cookie"))
            {
                cookieContainer = IsolatedStorageSettings.ApplicationSettings["cookieContainer"] as CookieContainer;
                Cookie cookie = IsolatedStorageSettings.ApplicationSettings["cookie"] as Cookie;
                if (cookieContainer.Count == 0 && cookie != null)
                {
                    cookieContainer.SetCookies(new Uri(Constant.ROOTURL), string.Format("{0}={1}", cookie.Name, cookie.Value));
                }
            }
            else
            {
                cookieContainer = new CookieContainer();
            }

            restRequest.CookieContainer = cookieContainer;
            client.BeginRequest(restRequest, (request, response, userState1) =>
            {
                cookieContainer = response.CookieContainer;
                CookieCollection cookies = cookieContainer.GetCookies(new Uri(Constant.ROOTURL));
                try
                {
                    IsolatedStorageSettings.ApplicationSettings["cookie"] = cookies["cooper"];
                    IsolatedStorageSettings.ApplicationSettings["cookieContainer"] = cookieContainer;
                    IsolatedStorageSettings.ApplicationSettings.Save();
                }
                catch
                {
                }

                if (response != null)
                    Deployment.Current.Dispatcher.BeginInvoke(action, response, userState1);
                else
                    Deployment.Current.Dispatcher.BeginInvoke(failed, new Exception("response返回为空!"));
            }, userState);
        }
开发者ID:codesharp,项目名称:cooper-mobi,代码行数:58,代码来源:WebRequestWrapper.cs


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