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


C# RestClient.AddDefaultHeader方法代码示例

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


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

示例1: RestSharpRestEngine

		public RestSharpRestEngine(string userAgent, int timeout)
		{
			_client = new RestSharp.RestClient(Endpoints.BaseApi)
			{
				PreAuthenticate = false
			};
			_client.AddDefaultHeader("accept", "*/*");
			_client.AddDefaultHeader("accept-encoding", "gzip,deflate");
            _client.UserAgent = userAgent;
			_client.ReadWriteTimeout = timeout;
		}
开发者ID:Goobles,项目名称:Discord.Net,代码行数:11,代码来源:RestClient.SharpRest.cs

示例2: GetUser

    UserInfo GetUser()
    {
        var client = new RestClient();
        client.BaseUrl = new Uri("http://localhost:60635");
        client.AddDefaultHeader("Content-Type", "application/json");
        client.AddDefaultHeader("Accept", "application/json");
        var request = new RestRequest();
        request.Resource = "api/Account/GetPlayer/player/ppowell";
        UserInfo user = client.Execute<UserInfo>(request).Data;

        return user;
    }
开发者ID:schoolsout,项目名称:simpleUnityWepAPIClient,代码行数:12,代码来源:WebAPI.cs

示例3: ConnectThroughProxy

 public void ConnectThroughProxy()
 {
     var client = new RestClient(@"https://api.test.nordnet.se/next/");
     IWebProxy proxy = WebRequest.DefaultWebProxy;
     proxy.Credentials = CredentialCache.DefaultCredentials;
     client.Proxy = proxy;
     client.AddDefaultHeader("Accept", "application/json");
     client.AddDefaultHeader("ContentType", "application/x-www-form-urlencoded");
     client.AddDefaultHeader("User-Agent","Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36");
     var restRequest = new RestRequest("login");
     IRestResponse response = client.Execute(restRequest);
     Console.Write(response.Content);
 }
开发者ID:JohanLarsson,项目名称:Next,代码行数:13,代码来源:ProxyPlayground.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: ToRestClient

        public static RestClient ToRestClient(this string baseAddress)
        {
            if(string.IsNullOrEmpty(baseAddress))
                throw new Exception("Base Address for http client cannot be empty");

            var client = new RestClient(baseAddress);
            client.AddDefaultHeader("Accept", JsonMediaType);
            client.AddDefaultHeader("Accept", XmlMediaType);
            client.AddDefaultHeader("Accept", HtmlMediaType);
            client.AddDefaultHeader("AcceptEncoding", GZipEncodingType);
            client.AddDefaultHeader("AcceptEncoding", DeflateEncodingType);
            return client;
        }
开发者ID:rjonker1,项目名称:lightstone-data-platform,代码行数:13,代码来源:RestClientExtensions.cs

示例6: 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

示例7: 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

示例8: SendGridMessage

        public static void SendGridMessage(SendGridMessage message)
        {
            var userName = ConfigurationManager.AppSettings["SendGrid:UserName"];
            var pwd = ConfigurationManager.AppSettings["SendGrid:Password"];
            var fromAddress = ConfigurationManager.AppSettings["SendGrid:SenderAddress"];
            var fromName = ConfigurationManager.AppSettings["SendGrid:SenderName"];
            var recipients = ConfigurationManager.AppSettings["SendGrid:Recipients"].Split(';');

            var baseUri = new Uri(baseUriString);
            var client = new RestClient(baseUri);
            client.AddDefaultHeader("Accept", "application/json");

            string destinations = string.Empty;

            var requestApiUrl = $"api/mail.send.json";

            var request = new RestRequest(requestApiUrl, Method.POST);
            request.AddParameter("api_user", userName);
            request.AddParameter("api_key", pwd);
            foreach (var recipient in recipients)
                request.AddParameter("to[]", recipient);
            request.AddParameter("subject", message.Subject);
            request.AddParameter("text", message.Text);
            request.AddParameter("from", fromAddress);
            request.AddParameter("fromname", fromName);

            var responseBGuest = client.Execute(request);
            if (responseBGuest.ErrorException != null)
            {
                var exception = responseBGuest.ErrorException;
                System.Console.WriteLine($"Bad response {exception}");
            }
        }
开发者ID:B-Guest,项目名称:IntegrationSamples-DotNet,代码行数:33,代码来源:SendMail.cs

示例9: SharpRestEngine

        public SharpRestEngine(DiscordAPIClientConfig config)
		{
			_config = config;
			_client = new RestSharp.RestClient(Endpoints.BaseApi)
			{
				PreAuthenticate = false,
				ReadWriteTimeout = _config.APITimeout,
				UserAgent = _config.UserAgent
			};
			if (_config.ProxyUrl != null)
				_client.Proxy = new WebProxy(_config.ProxyUrl, true, new string[0], _config.ProxyCredentials);
			else
				_client.Proxy = null;
            _client.RemoveDefaultParameter("Accept");
            _client.AddDefaultHeader("accept", "*/*");
			_client.AddDefaultHeader("accept-encoding", "gzip,deflate");
        }
开发者ID:hermanocabral,项目名称:Discord.Net,代码行数:17,代码来源:SharpRestEngine.cs

示例10: RestSharpEngine

        public RestSharpEngine(DiscordConfig config, string baseUrl, Logger logger)
		{
			_config = config;
            Logger = logger;

            _rateLimitLock = new AsyncLock();
            _client = new RestSharpClient(baseUrl)
			{
				PreAuthenticate = false,
				ReadWriteTimeout = _config.RestTimeout,
				UserAgent = config.UserAgent
            };
			_client.Proxy = null;
            _client.RemoveDefaultParameter("Accept");
            _client.AddDefaultHeader("accept", "*/*");
			_client.AddDefaultHeader("accept-encoding", "gzip,deflate");
        }
开发者ID:MarlboroTX,项目名称:Discord.Net,代码行数:17,代码来源:SharpRestEngine.cs

示例11: Setup

 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);
 }
开发者ID:Beetlebub,项目名称:twitch.net,代码行数:8,代码来源:DynamicClientTests.cs

示例12: Main

        private static void Main(string[] args)
        {
            var apiBaseUrl = args[0];
            var username = args[1];
            var password = args[2];
            var client = new RestClient(apiBaseUrl)
                {
                    Authenticator = new HttpBasicAuthenticator(username, password)
                };
            client.AddDefaultHeader("Accept", "application/json");

            Console.WriteLine("API base: " + apiBaseUrl);

            Console.WriteLine();
            Console.WriteLine("This sample will put a series of commands to the commands endpoint.");
            Console.WriteLine("The commands will update a Remotex workorder status, update title and creata an usagequantity/artikle row");
            Console.WriteLine("Operations used in this sample: POST");
            Console.WriteLine();
            Console.WriteLine("Press any key to begin...");
            Console.ReadKey();

            // The case "cases/130610-0027", resource "resources/130225-0011" and workorder reference "workorders/130610-0027-1"
            // are just example href based on the command xml files.

            // Based on UpdateWorkOrderStatus.xml
            var workOrderStatus = Commands.UpsertWorkOrder("workorders/130610-0027-1")
                                                .Parameter("State", "NotStarted"); // NotStarted/Started/Finished

            // Based on UpdateWorkOrderTitle.xml
            var workOrderTitleAndDescription = Commands.UpsertWorkOrder("workorders/130610-0027-1")
                    .Parameter("Title", "New title")
                    .Parameter("Description", "Updated using commands sample");

            // Based on CreateUsageQuantity.xml
            var addUsageQuantity = Commands.CreateUsageQuantity("cases/130610-0027", "resources/130225-0011",
                                                                new Dictionary<string, string>
                                                                    {
                                                                       { "Activity", "System.Picklist.UsageQuantity.Activity.Felsökning" },
                                                                       { "Description", "Demo lägga till text"}
                                                                    });

            var batch = CommandBatch.Create(new[] { workOrderStatus, workOrderTitleAndDescription, addUsageQuantity });

            var request = new RestRequest("commands", Method.POST) {RequestFormat = DataFormat.Json}
                .AddBody(batch);

            var commandResponse = client.Execute<CommandBatch>(request);

            Console.WriteLine("Status for update: " + commandResponse.StatusCode);
            if (commandResponse.StatusCode == HttpStatusCode.OK)
            {
                Console.WriteLine("Command successfull");
            }

            Console.WriteLine();
            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
开发者ID:remotex,项目名称:Samples,代码行数:58,代码来源:Program.cs

示例13: HeyWatchClient

        /// <summary>
        /// Create an HeyWatchClient instance
        /// </summary>
        /// <param name="Username"></param>
        /// <param name="Password"></param>
        /// <example>
        /// HeyWatchClient HeyWatch = new HeyWatchClient("username", "passwd");
        /// </example>
        public HeyWatchClient(string Username, string Password)
        {
            Cli = new RestClient("https://heywatch.com");
            Cli.Authenticator = new HttpBasicAuthenticator(Username, Password);
            Cli.AddDefaultHeader("Accept", "application/json");
            Cli.UserAgent = "HeyWatch dotnet/1.0.0";

            Json = new JavaScriptSerializer();
        }
开发者ID:jzhangnewsinc,项目名称:heywatch-dotnet,代码行数:17,代码来源:HeyWatch.cs

示例14: SmsTechWrapper

 public SmsTechWrapper(IRavenDocStore documentStore)
 {
     var smsTechUrl = ConfigurationManager.AppSettings["SMSTechUrl"];
     DocumentStore = documentStore;
     using (var session = DocumentStore.GetStore().OpenSession("Configuration"))
     {
         var smsTechConfiguration = session.Load<SmsTechConfiguration>("SmsTechConfig");
         if (smsTechConfiguration == null)
             throw new ArgumentException("Could not find sms tech configuration");
         TransmitSmsClient = new TransmitSms.TransmitSmsWrapper(smsTechConfiguration.ApiKey, smsTechConfiguration.ApiSecret, smsTechUrl);
         /* - ALL FOR CHECKING TRANSMIT SMS NUGET PACKAGE */
         var baseUrl = smsTechUrl;
         var authHeader = string.Format("Basic {0}", Convert.ToBase64String(Encoding.ASCII.GetBytes(string.Format("{0}:{1}", smsTechConfiguration.ApiKey, smsTechConfiguration.ApiSecret))));
         RestClient = new RestClient(baseUrl);
         RestClient.AddDefaultHeader("Authorization", authHeader);
         RestClient.AddDefaultHeader("Accept", "application/json");
     }
 }
开发者ID:Compassion,项目名称:SmsScheduler,代码行数:18,代码来源:ISmsTechWrapper.cs

示例15: StackExchange

        public StackExchange()
        {
            client = new RestClient
            {
                BaseUrl = apiRepo
            };

            client.AddDefaultHeader("Accept", "application/vnd.github.beta+json");
        }
开发者ID:arlm,项目名称:se-sharp,代码行数:9,代码来源:StackExchange.cs


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