本文整理汇总了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;
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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());
}
示例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;
}
示例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");
}
示例11: NewsRequests
public NewsRequests(string baseUrl)
{
client = new RestClient(baseUrl);
//client.Re
client.ClearHandlers();
client.AddHandler("application/json", new JsonDeserializer());
}
示例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();
}
示例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));
}
示例14: AuthenticationRequest
public AuthenticationRequest(string url)
{
client = new RestClient(url);
client.ClearHandlers();
client.AddHandler("application/json", new JsonDeserializer());
client.CookieContainer = RequestsHelper.GetCookieContainer();
}
示例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;
}