當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。