/// <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; }
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); }
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; }
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); }
/// <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; }
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; }
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; }
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()); }
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; }
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"); }
public RestClient() { _restClient = new RSharp.RestClient(); _restClient.ClearHandlers(); _restClient.AddHandler("application/json", new RSharp.Serialization.Json.JsonDeserializer()); // _fileLogs = System.Configuration.ConfigurationManager.AppSettings["Directory.Setup"] + @"RestClient.logs"; }
public NewsRequests(string baseUrl) { client = new RestClient(baseUrl); //client.Re client.ClearHandlers(); client.AddHandler("application/json", new JsonDeserializer()); }
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; }
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)); }
public BillsOfLadingReferenceCharges GetBillOfLadingReferenceCharges(ICollection<BillOfLadingChargeRequest> chargeRequests) { var AdvantumWebService = ConfigurationManager.AppSettings["AdvantumWS"]; var client = new RestClient(AdvantumWebService); var request = new RestRequest("getBlRefCharges.php", Method.GET); client.ClearHandlers(); client.AddHandler("application/xml", new XmlDeserializer()); string blReference = null; string storageTo = null; foreach (var item in chargeRequests) { blReference = string.IsNullOrEmpty(blReference) ? item.BLReferenceNumber.ToString() : blReference + "*" + item.BLReferenceNumber; storageTo = string.IsNullOrEmpty(storageTo) ? item.StorageToDate.ToString("yyyyMMdd") : storageTo + "*" + item.StorageToDate.ToString("yyyyMMdd"); } request.AddParameter("blreference", blReference); request.AddParameter("storageto", storageTo); var httpResponse = client.Execute(request); var systemResponse = new SystemResponse<BillsOfLadingReferenceCharges>(); //this will throw fault exceptions if it failscd systemResponse = DeserializationHelpers.ProcessWebServiceResponse<BillsOfLadingReferenceCharges>(httpResponse); //otherwise results will be returned as per usual return systemResponse.Result; }
/// <summary> /// Confirm a newly-created subscription, pre-authorzation or one-off /// payment. This method also checks that the resource response data includes /// a valid signature and will throw a {SignatureException} if the signature is /// invalid. /// </summary> /// <param name="requestContent">the response parameters returned by the API server</param> /// <returns>the confirmed resource object</returns> public ConfirmResource ConfirmResource(NameValueCollection requestContent) { var resource = DeserializeAndValidateRequestSignature(requestContent); var request = new RestRequest("confirm", Method.POST); request.RequestFormat = DataFormat.Json; request.AddBody( new { resource_id = resource.ResourceId, resource_type = resource.ResourceType }); var client = new RestClient { BaseUrl = new System.Uri(ApiClient.ApiUrl), UserAgent = GoCardless.UserAgent }; var serializer = new JsonSerializer { ContractResolver = new UnderscoreToCamelCasePropertyResolver(), }; client.AddHandler("application/json", new NewtonsoftJsonDeserializer(serializer)); client.Authenticator = new HttpBasicAuthenticator(GoCardless.AccountDetails.AppId, GoCardless.AccountDetails.AppSecret); var response = client.Execute(request); if (response.StatusCode != HttpStatusCode.OK) { throw new ApiException("Unexpected response : " + (int)response.StatusCode + " " + response.StatusCode); } return resource; }
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(); }
public Sprintly() { client = new RestSharp.RestClient("https://sprint.ly/api"); client.Authenticator = new HttpBasicAuthenticator("email", "api key"); client.RemoveHandler("application/json"); client.AddHandler("application/json", new SprintlyJsonDeserializer()); }
public AuthenticationRequest(string url) { client = new RestClient(url); client.ClearHandlers(); client.AddHandler("application/json", new JsonDeserializer()); client.CookieContainer = RequestsHelper.GetCookieContainer(); }
public void Setup() { _restClient = new RestClient(_twitchApiUrl); _restClient.AddHandler("application/json", new DynamicJsonDeserializer()); _restClient.AddDefaultHeader("Accept", _twitchAcceptHeader); Func<string, Method, IRestRequest> requestFunc = (url, method) => new RestRequest(url, method); _twitchClient = new TwitchReadOnlyClient(_restClient, requestFunc); }
public NewsRequests(string baseUrl) { client = new RestClient(baseUrl); client.ClearHandlers(); client.AddHandler("application/json", new JsonDeserializer()); client.CookieContainer = RequestsHelper.GetCookieContainer(); }
public TMDbClient(string apiKey) { this.apiKey = apiKey; client = new RestClient(BaseUrl); client.AddDefaultParameter("api_key", apiKey, ParameterType.QueryString); client.ClearHandlers(); client.AddHandler("application/json", new JsonDeserializer()); }
private static RestSharpRestClient BuildRestClientSync(IRestConnection restConnection) { var client = new RestSharpRestClient { BaseUrl = restConnection.BaseUrl, Timeout = restConnection.Timeout, Authenticator = restConnection.AuthenticateSync <IAuthenticator>() }; // use Newtonsoft's for a) proper handling of DateTimeOffset types, b) performance and c) extensability client.AddHandler("application/json", NewtonsoftJsonSerializer.Default); client.AddHandler("text/json", NewtonsoftJsonSerializer.Default); client.AddHandler("text/x-json", NewtonsoftJsonSerializer.Default); client.AddHandler("text/javascript", NewtonsoftJsonSerializer.Default); client.AddHandler("*+json", NewtonsoftJsonSerializer.Default); return(client); }
public JiraApiClient(JiraSettings jiraSettings) { _baseUrl = jiraSettings.BaseUrl; _restClient = new RestClient(new Uri(jiraSettings.BaseUrl, "rest/api/2")) { Authenticator = new HttpBasicAuthenticator(jiraSettings.UserName, jiraSettings.Password) }; _restClient.AddHandler("application/json", new DynamicJsonDeserializer()); }
/// <summary> /// Default Constructor for the BitClient /// </summary> /// <param name="apiKey">The Api Key to use for the BandsInTown Requests</param> public BitClient(string apiKey) { _apiKey = apiKey; _restClient = new RestClient(_baseUrl); _restClient.ClearHandlers(); _restClient.AddHandler("application/xml", new XmlAttributeDeserializer()); //probly not needed... RequestCount = 0; DataCount = 0; }
private void LoadClient() { _restClient = new RestClient(DropNet.Resource.SecureLoginBaseUrl); _restClient.ClearHandlers(); _restClient.AddHandler("*", new JsonDeserializer()); //probly not needed... RequestCount = 0; DataCount = 0; _requestHelper = new RequestHelper(_version); }
//private const string BaseUrl = @"http://localhost/API/"; public static void GetSuggestions(Action<List<String>> callback, string term) { var client = new RestClient(BaseUrl); client.ClearHandlers(); client.AddHandler("application/json", new JsonDeserializer()); var request = new RestRequest("autocomplete"); request.AddParameter("term", term); client.ExecuteAsync<List<String>>(request, response => callback(response.Data)); }
//Bulk.CreateCustomObjectData(int customObjectId, int importId) ///customObjects/{parentId}/imports/{id}/data public static IRestClient CreateClient(string site, string username, string password, Uri baseUri) { var restClient = new RestClient { BaseUrl = baseUri, Authenticator = new HttpBasicAuthenticator(site + "\\" + username, password) }; restClient.AddHandler("text/plain", new JsonDeserializer()); return restClient; }
internal ClientBase(string publicKey, string privateKey) { _publicKey = publicKey; _privateKey = privateKey; CreateRequestClient = () => { var client = new RestClient(BaseUrl); client.AddHandler("application/json", new DynamicJsonDeserializer()); return client; }; }
public static List<CompleteSuggestion> GetSuggestions(string text) { RestClient r = new RestClient("http://google.com/complete/search"); RestRequest req = new RestRequest(); req.AddParameter("q", text); req.AddParameter("output", "toolbar"); req.RequestFormat = DataFormat.Xml; r.AddHandler("text/xml", new GoogleXmlDeserializer()); return r.Execute<List<CompleteSuggestion>>(req).Data; }
public ConsumerViewService(RestClient client) { if (client == null) throw new ArgumentNullException("client", "The RestClient instance must be injected or initialized manually."); // Replace the default deserialization handler client.AddHandler("application/json", new PCubedJsonDeserializer()); Client = client; Configuration = new ConfigurationProvider(); }
private static RestClient InitializeRestClient(string baseUrl, string localEducationAgency, string username, string password) { CookieContainer cookieContainer = new CookieContainer(); RestClient client = new RestClient(baseUrl); client.AddHandler("application/json", new JsonDotNetSerializer()); client.FollowRedirects = true; client.CookieContainer = cookieContainer; string entryUrl = Website.LocalEducationAgency.Entry(localEducationAgency) .Replace(baseUrl, string.Empty, StringComparison.InvariantCultureIgnoreCase); RestRequest request = new RestRequest(entryUrl); request.AddHeader("Accept", "text/html"); var response = client.Execute(request); string content = response.Content; string relativePath = GetContextPath(response.ResponseUri); var loginResponse = ProcessAndSubmitForm(relativePath, content, cookieContainer, s => { string fieldName = s.ToLower(); if (fieldName.Contains("username")) return username; if (fieldName.Contains("password")) return password; return null; }); var streamReader = new StreamReader(loginResponse.GetResponseStream()); string html = streamReader.ReadToEnd(); if (!html.Contains(@"name=""hiddenform""")) throw new Exception("Login attempt failed."); relativePath = GetContextPath(loginResponse.ResponseUri); CookieContainer siteCookieContainer = new CookieContainer(); var mainSiteSubmissionResponse = ProcessAndSubmitForm(relativePath, html, siteCookieContainer, s => null, true); streamReader = new StreamReader(mainSiteSubmissionResponse.GetResponseStream()); string html2 = streamReader.ReadToEnd(); client.CookieContainer = siteCookieContainer; return client; }
private IRestResponse <T> GetResponse <T>(string resource, object body = null, Method method = Method.GET, IEnumerable <KeyValuePair <string, string> > headers = null) where T : new() { var client = new RestSharp.RestClient(this.baseUrl); client.AddHandler("application/json", new CustomJsonDeserializer()); var request = BuildRequest(resource, method, body, headers); //var x = client.Execute(request); return(client.Execute <T>(request)); }
public IRestClient CreateRestClient(Uri baseUri) { // TODO: We are creating a new client per request // as one client can contact only one baseUri. // This is not very bad but it might still be worth // it to cache clients per baseUri in the future. var restClient = new RestSharp.RestClient(baseUri) { FollowRedirects = true }; restClient.AddHandler("application/json", new RestJsonDeserializer()); return(restClient); }
public IRestResponse GetRestSharpResponse() { var client = new RestSharp.RestClient(); client.ClearHandlers(); client.BaseUrl = new Uri("http://api.zippopotam.us"); client.AddHandler("text/html", new JsonDeserializer()); var request = new RestRequest(); //request.Resource = "api/1.1/searchPlants"; request.AddParameter("location", 5332921); request.AddParameter("limit", 10); request.AddParameter("color", "red"); //request.AddParameter("format", "json"); var plants = client.Execute <PowerPlantsDTO>(request); return(plants); }
private void InitializeDefaults(string baseUrl) { DecoratedClient = new RestSharp.RestClient(baseUrl); DecoratedClient.AddHandler("application/json", new CustomJsonSerializer()); DecoratedClient.UserAgent = "Sillycore.RestClient"; }
public RestClient(Uri baseAddress, Uri resource) : base(baseAddress, resource) { _restClient = new RSharp.RestClient(baseAddress); _restClient.ClearHandlers(); _restClient.AddHandler("application/json", new RSharp.Serialization.Json.JsonDeserializer()); }
static async Task Main(string[] args) { var config = new ConfigurationBuilder() .AddJsonFile(args[0]) .Build(); var rs = new RestSharp.RestClient(config["ConfluenceUrl"]); rs.Authenticator = new HttpBasicAuthenticator(config["User"], config["Token"]); rs.ClearHandlers(); var serializer = new JsonSerializer(); rs.AddHandler("application/json", new NewtonsoftDeserializer(serializer)); var container = BuildContainer(rs, config, args[0]); var pageUrl = $"/rest/api/content?expand=body,body.atlas_doc_format,container,metadata.properties,ancestors&spaceKey={config["SpaceKey"]}&limit=100"; var reporter = new ErrorReporter(); int totalPages = 0; int ignoredPages = 0; var rules = CreateRuleSet(container); var ignoredPaths = config.GetSection("Ignore") .GetChildren() .Select(x => x.Value) .ToList(); var debugPages = config.GetSection("DebugPages").GetChildren().Select(x => x.Get <string>()).ToList(); while (!string.IsNullOrWhiteSpace(pageUrl)) { var response = await rs.ExecuteGetTaskAsync <Paged <Page> >(new RestRequest(pageUrl)); foreach (var page in response.Data.Results) { if (page.Ancestors.ElementAtOrDefault(1)?.Title != config["CheckRoot"]) { continue; } var path = page.GetPath(); if (ignoredPaths.Any(x => path.StartsWith(x, StringComparison.CurrentCultureIgnoreCase))) { Console.WriteLine($"Ignoring {path}"); ignoredPages++; continue; } if (debugPages.Contains(page.Id)) { System.Diagnostics.Debugger.Break(); } foreach (var rule in rules) { try { rule.Check(page, reporter); } catch (Exception e) { reporter.Report(page, $"Rule {rule.GetType().Name} failed with {e.Message}"); } } } Console.WriteLine(response.Data._links?.Next); pageUrl = response.Data._links?.Next; totalPages += response.Data.Results.Count; } reporter.SendErrorsTo(container.Resolve <ConsoleErrorTarget>()); Console.WriteLine($"{totalPages} pages in total"); Console.WriteLine($"{totalPages - ignoredPages} pages checked"); Console.WriteLine($"{ignoredPages} pages ignored"); Console.WriteLine($"{reporter.ErrorsCount} errors reported"); }
public JsonResult GetAiQiYiURL(string voteid, bool repeatget = true) { VideoInfo videoInfo = null; _iqiyiclient = new RestSharp.RestClient("http://openapi.iqiyi.com"); _iqiyiclient.AddHandler("application/json", new RestSharp.Deserializers.JsonDeserializer()); if (DateTime.Now > overDate || tokeninfo == null) { var req = new RestSharp.RestRequest("/api/iqiyi/authorize", RestSharp.Method.GET); //接口参数 req.AddParameter("client_id", clientid); req.AddParameter("client_secret", clientsecret); try { var response = _iqiyiclient.Execute(req); if (response.StatusCode == HttpStatusCode.OK) { var json = response.Content.Replace("\\", ""); json = json.Substring(1, json.Length - 2); var data = Newtonsoft.Json.JsonConvert.DeserializeObject <BaseInfo <TokenInfo> >(json); if (data != null && data.code == "A00000") { overDate = DateTime.Now.AddSeconds(data.data.expires_in); tokeninfo = data.data; } } else { return(Json(videoInfo, JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { return(Json(videoInfo, JsonRequestBehavior.AllowGet)); } } if (tokeninfo != null) { var req = new RestSharp.RestRequest("/api/file/fullStatus", RestSharp.Method.GET); //接口参数 req.AddParameter("access_token", tokeninfo.access_token); req.AddParameter("file_id", voteid); try { var response = _iqiyiclient.Execute(req); if (response.StatusCode == HttpStatusCode.OK) { var json = response.Content.Replace("\\", ""); json = json.Substring(1, json.Length - 2); var data = Newtonsoft.Json.JsonConvert.DeserializeObject <BaseInfo <VideoInfo> >(json); if (data != null && data.code == "A00000") { data.data.m3u896 = data.data.urllist.m3u8[96].ToString(); var mp4Client = new RestSharp.RestClient(); mp4Client.AddHandler("application/json", new RestSharp.Deserializers.JsonDeserializer()); var reqmp4 = new RestSharp.RestRequest(data.data.urllist.mp4[2], RestSharp.Method.GET); var repsonsemp4url = mp4Client.Execute(reqmp4); try { if (repsonsemp4url.StatusCode == HttpStatusCode.OK) { json = repsonsemp4url.Content; var i = json.IndexOf('{'); var f = json.LastIndexOf(";"); json = json.Substring(i, f - i); var mp4urldata = Newtonsoft.Json.JsonConvert.DeserializeObject <BaseInfo <MP4Info> >(json); if (mp4urldata.code == "A00000") { data.data.mp42 = mp4urldata.data.l; } else { data.data.mp42 = ""; } } } catch (Exception ex) { //_logger.Error("获取MP4地址错误1:" + ex.ToString()); throw ex; } videoInfo = data.data; } else if (data != null && data.code == "A00007") { if (repeatget) { var repdata = Newtonsoft.Json.JsonConvert.DeserializeObject <BaseInfo <RepeatVideo> >(json); if (repdata != null && repdata.data != null && repdata.data.fileIdBefore.Length == 32) { return(GetAiQiYiURL(repdata.data.fileIdBefore, false)); } } } } } catch (Exception ex) { throw ex; } } return(Json(videoInfo, JsonRequestBehavior.AllowGet)); }