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


C# RestRequest.AddHeader方法代码示例

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


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

示例1: GetQuoteRestSharp

        private static async Task<Quote> GetQuoteRestSharp()
        {
            var uri = new Uri("https://andruxnet-random-famous-quotes.p.mashape.com/?cat=movies");
            using (var client = new RestSharp.Portable.HttpClient.RestClient(uri))
            {
                var request = new RestRequest(Method.POST);
                request.AddHeader("X-Mashape-Key", "SVRrKUoLRBmshZ7IANqnF4kmkxt7p1kYcMNjsnWxDGnoyCOUwh");
                //request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
                request.AddHeader("Accept", "application/json");

                var response = await client.Execute<Quote>(request);
                var quote = await Task.Run(() => new JsonDeserializer().Deserialize<Quote>(response));
                return quote;
            }
        }
开发者ID:thshr,项目名称:XamarinFormsApp,代码行数:15,代码来源:Program.cs

示例2: UpdateComponentStatusAsync

 public Task<Component> UpdateComponentStatusAsync(string roomId, string deviceId, bool status)
 {
     var request = new RestRequest("components?roomId={roomId}&deviceId={deviceId}&status={status}") {Method = HttpMethod.Put};
     request.AddUrlSegment("roomId", roomId)
         .AddUrlSegment("deviceId", deviceId)
         .AddUrlSegment("status", status);
     request.AddHeader("Content-Type", "application/json");
     var task = _client.Execute<Component>(request).ContinueWith(t => t.Result.Data);
     return task;
 }
开发者ID:ywchang,项目名称:SmartHotel,代码行数:10,代码来源:ComponentRestServiceRepositoryAsync.cs

示例3: Execute

		public static async Task<JObject> Execute(string callback, HttpMethod httpMethod,
									  			  Dictionary<string,string> parameters, 
									  			  Dictionary<string,string> files = null, object obj = null)
		{
			//init request
			var request = new RestRequest (callback, httpMethod);
			request.AddHeader("Content-Type", "application/json; charset=utf-8");


			//add parameters
			foreach (var key in parameters.Keys) 
			{
				request.AddParameter (key, parameters [key].ToString ());
			}
			

			//add files
			//if (files != null && files.Keys.Count > 0) {
			//	foreach (var key in files.Keys) {
			//		request.AddFile( .AddFile (key, files[key]);
			//	}
			//}


			//execute
			var result = await client.Execute<string>(request);


			//print response
			Debug.WriteLine (callback);
			Debug.WriteLine (result.Data);


			//save cookies
			//var sessionCookie = response.Cookies.SingleOrDefault(x => x.Name == "WRAD_SESSION");
			//if (sessionCookie != null && APIHelper.restClient.CookieContainer==null)
			//{
			//	APIHelper.restClient.CookieContainer = new CookieContainer ();
			///	APIHelper.restClient.CookieContainer.Add(new Uri(APIHelper.baseUrl),new Cookie(sessionCookie.Name, sessionCookie.Value, sessionCookie.Path, sessionCookie.Domain));
			//}


			//string to JObect deserialization
			try{
				return JObject.Parse(result.Data);
			} catch(Exception ex){
				Debug.WriteLine (ex.Message + (ex.InnerException != null ? ("\n" + ex.InnerException.Message) : ""));
				return null;
			}
		}
开发者ID:Dallas92,项目名称:HOLA,代码行数:50,代码来源:API.cs

示例4: loginUser

        /// <summary>
        /// Permet la connexion du joueur
        /// </summary>
        /// <param name="userNotLog">l'objet User contenant le joueur voulant se connecter</param>
        /// <returns></returns>
        public async Task<dynamic> loginUser(User userNotLog)
        {
            RestRequest request = new RestRequest("user/login", Method.POST);

            request.AddHeader("Content-Type", "application/json");
            request.AddJsonBody(userNotLog);
            _client.IgnoreResponseStatusCode = true;
            var response = await _client.Execute<dynamic>(request);
            var data = Encoding.UTF8.GetString(response.RawBytes);
            //Permet de recuperer le message d'erreur avant que le tache se termine
            if (!response.IsSuccess){
                throw new Exception(data);
            }
            return data;
        }
开发者ID:fetristan,项目名称:Audatia-Test,代码行数:20,代码来源:APIAudatia.cs

示例5: passwordForgot

        public async Task<dynamic> passwordForgot(string mail)
        {
            RestRequest request = new RestRequest("user/passwordforgot", Method.POST);

            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("mail", mail, ParameterType.RequestBody, "application/json");
            _client.IgnoreResponseStatusCode = true;
            var response = await _client.Execute<dynamic>(request);
            var data = Encoding.UTF8.GetString(response.RawBytes);
            //Permet de recuperer le message d'erreur avant que le tache se termine
            if (!response.IsSuccess)
            {
                throw new Exception(data);
            }
            return data;
        }
开发者ID:fetristan,项目名称:Audatia-Test,代码行数:16,代码来源:APIAudatia.cs

示例6: UnShim

        /// <summary>
        /// Converts this instance to an IRestRequest
        /// </summary>
        internal IRestRequest UnShim()
        {
            var req = new RestRequest(this.Resource, Unshim(this.Method));

            if (!this.CsrfToken.IsBlank())
                req.AddHeader("X-CSRF-Token", this.CsrfToken);

            if (this.Body != null)
                req.AddJsonBody(this.Body);

            if (this.Cookies != null)
                foreach (var cookie in this.Cookies)
                    req.AddParameter(cookie.Key, cookie.Value, ParameterType.Cookie);

            if (this.Parameters != null)
            {
                //if (this.Parameters.Count > 0)
                //	req.AddHeader("Content-Type", "application/x-www-form-urlencoded");

                foreach (var param in this.Parameters)
                    req.AddParameter(param.Key, param.Value, ParameterType.RequestBody);
            }



            //later: try this for attaching files to nodes:
            //req.ContentCollectionMode = ContentCollectionMode.MultiPartForFileParameters;


            //req.RequestFormat = DataFormat.Json; <--- Drupal ignores this

            //if (this.Attachment != null)
            //{
            //	req.AddFile(this.Attachment.Name, 
            //				this.Attachment.Stream, 
            //				this.Attachment.Name, 
            //				MediaTypeHeaderValue.Parse("multipart/form-data"));

            //	req.AddParameter("field_name", "field_private_file");//hack: hard-code!
            //	//req.AddParameter("files[files]", "@" + this.Attachment.Name);
            //}

            return req;
        }
开发者ID:peterson1,项目名称:ErrH,代码行数:47,代码来源:RequestShim.cs

示例7: CreateGetFileRequest

        public RestRequest CreateGetFileRequest(string path, string root, long startByte, long endByte, string rev)
        {
            var request = new RestRequest("{version}/files/{root}{path}", HttpMethod.Get);
            request.AddParameter("version", _version, ParameterType.UrlSegment);
            request.AddParameter("path", path, ParameterType.UrlSegment);
            request.AddParameter("root", root, ParameterType.UrlSegment);
            request.AddParameter("rev", rev, ParameterType.UrlSegment);
            request.AddHeader("Range", "bytes=" + startByte + "-" + endByte);

            return request;
        }
开发者ID:gabornemeth,项目名称:DropNet,代码行数:11,代码来源:RequestHelper.cs


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