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


C# RestClient.AddHandler方法代码示例

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


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

示例1: Create

        /// <summary>
        /// Simply returns a new RestClient() object.
        /// </summary>
        public IRestClient Create(IConfiguration config)
        {
            string userName = config.Authorization.UserName;
            string password = config.Authorization.Password;

            string userAgent = config.UserAgent;

            if (String.IsNullOrWhiteSpace(userAgent))
                userAgent = String.Format("3Seventy SDK.NET {0}", m_version);

            // TODO: As of RestSharp 105.x you have to supply a base URL here!

            var rval = new RestClient
            {
                Authenticator = new HttpBasicAuthenticator(userName, password),
                UserAgent = userAgent,
                Timeout = (int)config.Timeout.TotalMilliseconds
            };

            rval.ClearHandlers();
            rval.AddHandler("application/json", new NewtonsoftSerializer());
            rval.AddHandler("text/json", new NewtonsoftSerializer());

            rval.AddHandler("application/xml", new XmlDeserializer());
            rval.AddHandler("text/xml", new XmlDeserializer());

            return rval;
        }
开发者ID:pankhuri3,项目名称:vector370-dotnet,代码行数:31,代码来源:DefaultRestClientFactory.cs

示例2: findPatient

        public static Patient findPatient(string firstName, string lastName, string birthDate, string streetAddress, string gender, string phoneNumber)
        {
            List<Tuple<string, string>> stringParams = generateParamsList(firstName, lastName, birthDate, streetAddress, gender, phoneNumber);

            var client = new RestClient("https://open-ic.epic.com/FHIR/api/FHIR/DSTU2/");
            client.ClearHandlers();
            client.AddHandler("application/xml", new XmlDeserializer());
            client.AddHandler("text/xml", new XmlDeserializer());

            var request = new RestRequest("Patient");
            request.RequestFormat = DataFormat.Xml;
            foreach (Tuple<string, string> param in stringParams)
            {
                request.AddParameter(param.Item1, param.Item2);
            }

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

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(content);
            string jsonString = Newtonsoft.Json.JsonConvert.SerializeXmlNode(doc);
            dynamic json = (dynamic) JsonConvert.DeserializeObject(jsonString);
            // if there are multiple users, pick one functionality goes here
            string id = json.Bundle.entry.link.url["@value"];
            id = id.Replace("https://open-ic.epic.com/FHIR/api/FHIR/DSTU2/Patient/", "");
            json = json.Bundle.entry.resource.Patient;
            return createPatientFromJson(json, id);
        }
开发者ID:Maast3r,项目名称:Epic-BoilerMake,代码行数:29,代码来源:Patient.cs

示例3: GetBasicClient

        private IRestClient GetBasicClient(string baseUrl, string userAgent)
        {
            var client = new RestClient(baseUrl);
            client.UserAgent = userAgent;

            // Harvest API is inconsistent in JSON responses so we'll stick to XML
            client.ClearHandlers();
            client.AddHandler("application/xml", new HarvestXmlDeserializer());
            client.AddHandler("text/xml", new HarvestXmlDeserializer());

            return client;
        }
开发者ID:fcbenoit,项目名称:harvest.net,代码行数:12,代码来源:RestSharpFactory.cs

示例4: RecurlyClient

        public RecurlyClient(string sAPIKey)
        {
            mRESTClient = new RestClient();
            mRESTClient.BaseUrl = RECURLY_BASE_URL;
            mRESTClient.AddDefaultHeader("Accept", "application/xml");
            mRESTClient.AddDefaultHeader("Content-Type", "application/xml; charset=utf-8");
            mRESTClient.Authenticator = new HttpBasicAuthenticator(sAPIKey, string.Empty);

            mSerializer = new YAXRestSerializer();

            mRESTClient.AddHandler("application/xml", mSerializer);
            mRESTClient.AddHandler("text/xml", mSerializer);
        }
开发者ID:ehramovich,项目名称:RecurlyClient,代码行数:13,代码来源:RecurlyClient.cs

示例5: findPerscriptions

        public static List<Perscription> findPerscriptions(string patientId)
        {
            List<Perscription> perscriptions = new List<Perscription>();

            var client = new RestClient("https://open-ic.epic.com/FHIR/api/FHIR/DSTU2/");
            client.ClearHandlers();
            client.AddHandler("application/xml", new XmlDeserializer());
            client.AddHandler("text/xml", new XmlDeserializer());

            var request = new RestRequest("MedicationPrescription");
            request.AddParameter("patient", patientId);
            request.AddParameter("status", "active");

            request.RequestFormat = DataFormat.Xml;

            IRestResponse response = client.Execute(request);
            var content = response.Content;
            if (content == "")
            {
                return perscriptions;
            }

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(content);
            string jsonString = Newtonsoft.Json.JsonConvert.SerializeXmlNode(doc);
            dynamic json = JsonConvert.DeserializeObject(jsonString);

            json = json.Bundle.entry;
            if (json != null)
            {
                if (json.Count > 1)
                {
                    foreach (dynamic perscriptionJson in json)
                    {
                        string id = perscriptionJson.link.url["@value"];
                        id = id.Replace("https://open-ic.epic.com/FHIR/api/FHIR/DSTU2/MedicationPrescription/", "");
                        Perscription perscription = getPerscriptionFromJson(perscriptionJson.resource.MedicationPrescription, id);
                        perscriptions.Add(perscription);
                    }
                }
                else
                {
                    string id = json.link.url["@value"];
                    id = id.Replace("https://open-ic.epic.com/FHIR/api/FHIR/DSTU2/MedicationPrescription/", "");
                    Perscription perscription = getPerscriptionFromJson(json.resource.MedicationPrescription, id);
                    perscriptions.Add(perscription);
                }
            }
            return perscriptions;
        }
开发者ID:Maast3r,项目名称:Epic-BoilerMake,代码行数:50,代码来源:Perscription.cs

示例6: CreateRestClient

        /// <summary>
        /// Creates a new <see cref="IRestClient"/> with <see cref="RestSharp.Deserializers.IDeserializer" /> handlers.
        /// </summary>
        /// <returns></returns>
        IRestClient CreateRestClient(IDeserializer deserializer)
        {
            var client = new RestClient(options.ApiAddress);

            client.ClearHandlers();

            client.AddHandler("application/json", deserializer);
            client.AddHandler("text/json", deserializer);
            client.AddHandler("text/x-json", deserializer);
            client.AddHandler("text/javascript", deserializer);
            client.AddHandler("*+json", deserializer);

            return client;
        }
开发者ID:Elders,项目名称:Pushnotifications,代码行数:18,代码来源:RestClient.cs

示例7: CreateRestClient

        public IRestClient CreateRestClient(string baseUrl)
        {
            var restClient = new RestClient(baseUrl);

            restClient.UseSynchronizationContext = false;

            // Just use a lightweight wrapper around Newtonsoft deserialization since
            // we've had problems with RestSharp deserializers in the past.
            restClient.AddHandler(Constants.JsonApplicationContent, new JsonSerializer());
            restClient.AddHandler(Constants.JsonTextContent, new JsonSerializer());
            restClient.AddHandler(Constants.XJsonTextContent, new JsonSerializer());

            return restClient;
        }
开发者ID:akilb,项目名称:NGitHub,代码行数:14,代码来源:RestClientFactory.cs

示例8: ApiClient

        public ApiClient()
        {
            BaseUrl = ConfigurationManager.AppSettings.TestUrl() + "/api/v1/";

            client = new RestClient(BaseUrl);
            client.AddHandler("application/json", new JsonCamelCaseDeserializer());

            // Only get one handler per content type so easiest just to have 2
            // clients
            dynamicClient = new RestClient(BaseUrl);
            dynamicClient.AddHandler("application/json", new DynamicJsonDeserializer());

            backdoorClient = new RestClient(ConfigurationManager.AppSettings.TestUrl() + "/api/backdoor");
            dynamicClient.AddHandler("application/json", new JsonCamelCaseDeserializer());
        }
开发者ID:rdingwall,项目名称:100books,代码行数:15,代码来源:ApiClient.cs

示例9: CreateRestClient

        public IRestClient CreateRestClient(string baseUrl)
        {
            var restClient = new RestClient(baseUrl);

            restClient.UseSynchronizationContext = false;

            // RestSharp uses a json deserializer that does not use attribute-
            // based deserialization by default. Therefore, we substitute our
            // own deserializer here...
            restClient.AddHandler(Constants.JsonApplicationContent, new CustomJsonSerializer());
            restClient.AddHandler(Constants.JsonTextContent, new CustomJsonSerializer());
            restClient.AddHandler(Constants.XJsonTextContent, new CustomJsonSerializer());

            return restClient;
        }
开发者ID:ninjaAB,项目名称:NGitHub,代码行数:15,代码来源:RestClientFactory.cs

示例10: TwitchRestClient

		public TwitchRestClient(IConfig config)
		{
			_config = config;
			_restClient = new RestClient(_TWITCH_API_URL);
			_restClient.AddHandler("application/json", new JsonDeserializer());
			_restClient.AddDefaultHeader("Accept", "application/vnd.twitchtv.v3+json");
		}
开发者ID:TedCrocker,项目名称:BallouBot,代码行数:7,代码来源:TwitchRestClient.cs

示例11: NewsRequests

 public NewsRequests(string baseUrl)
 {
     client = new RestClient(baseUrl);
     //client.Re
     client.ClearHandlers();
     client.AddHandler("application/json", new JsonDeserializer());
 }
开发者ID:HackatonArGP,项目名称:Guardianes,代码行数:7,代码来源:NewsRequests.cs

示例12: Load

        protected override void Load(ContainerBuilder builder)
        {
            builder.RegisterType<TwitchClientFactory>().As<ITwitchClientFactory>().SingleInstance();
            builder.Register<Func<string, Method, IRestRequest>>(c => (uri, method) =>
                                                                      {
                                                                          var request = new RestRequest(uri, method);
                                                                          //Add any client or auth tokens here
                                                                          //request.AddHeader("Client-ID", "");
                                                                          //request.AddHeader("Authorization", string.Format("OAuth {0}", "oauth-token"));
                                                                          return request;
                                                                      }).AsSelf().SingleInstance();
            builder.Register(c =>
                             {
                                 var restClient = new RestClient("https://api.twitch.tv/kraken");
                                 restClient.AddHandler("application/json", new DynamicJsonDeserializer());
                                 restClient.AddDefaultHeader("Accept", "application/vnd.twitchtv.v2+json");
                                 return restClient;
                             }).As<IRestClient>().SingleInstance();
            builder.Register(c =>
                             {
                                 var restClient = c.Resolve<IRestClient>();
                                 var requestFactory = c.Resolve<Func<string, Method, IRestRequest>>();
                                 return c.Resolve<ITwitchClientFactory>().CreateStaticReadonlyClient(restClient, requestFactory);
                             }).InstancePerHttpRequest();

        }
开发者ID:Beetlebub,项目名称:twitch.net,代码行数:26,代码来源:TwitchModule.cs

示例13: GetPersons

 public void GetPersons(Action<List<Person>> callback)
 {
     var client = new RestClient("https://raw.github.com/bekkopen/dotnetkurs/master/PersonPhoneApp/");
     client.AddHandler("text/plain", new JsonDeserializer());
     var request = new RestRequest("Persons.json", Method.GET) {RequestFormat = DataFormat.Json};
     client.ExecuteAsync<List<Person>>(request, response => callback(response.Data));
 }
开发者ID:aasmundeldhuset,项目名称:dotnetkurs,代码行数:7,代码来源:PersonsRestClient.cs

示例14: AuthenticationRequest

 public AuthenticationRequest(string url)
 {
     client = new RestClient(url);
     client.ClearHandlers();
     client.AddHandler("application/json", new JsonDeserializer());
     client.CookieContainer = RequestsHelper.GetCookieContainer();
 }
开发者ID:HackatonArGP,项目名称:Guardianes,代码行数:7,代码来源:AuthenticationRequest.cs

示例15: GetCustomerBillsOfLading

        public CustomerBillsOfLading GetCustomerBillsOfLading(UserDetails userDetails)
        {
            //check input methods here
            //user details are both not null
            //throw fault exception
            ValidationHelpers.ValidateUserDetails(userDetails);

            var AdvantumWebService = ConfigurationManager.AppSettings["AdvantumWS"];

            var httpRequestclient = new RestClient(AdvantumWebService);
            var webServiceMethodRequest = new RestRequest("GetCustomerBls.php", Method.GET);
            httpRequestclient.ClearHandlers();
            httpRequestclient.AddHandler("application/xml", new XmlDeserializer());

            webServiceMethodRequest.AddParameter("username", userDetails.UserName);
            webServiceMethodRequest.AddParameter("password", userDetails.PassWord);

            var httpResponse = httpRequestclient.Execute(webServiceMethodRequest);

            var systemResponse = new SystemResponse<CustomerBillsOfLading>();

            //this will throw fault exceptions if it failscd
            systemResponse = DeserializationHelpers.ProcessWebServiceResponse<CustomerBillsOfLading>(httpResponse);

            //otherwise results will be returned
            return systemResponse.Result;
        }
开发者ID:Kingston-Wharves,项目名称:TestProjects,代码行数:27,代码来源:EpayServiceRest.cs


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