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


C# RestSharp.HttpResponse类代码示例

本文整理汇总了C#中RestSharp.HttpResponse的典型用法代码示例。如果您正苦于以下问题:C# HttpResponse类的具体用法?C# HttpResponse怎么用?C# HttpResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: ResponseCallback

		private void ResponseCallback(IAsyncResult result, Action<HttpResponse> callback)
		{
			var response = new HttpResponse {ResponseStatus = ResponseStatus.None};

			try
			{
				if(_timeoutState.TimedOut)
				{
					response.ResponseStatus = ResponseStatus.TimedOut;
					ExecuteCallback(response, callback);
					return;
				}

				GetRawResponseAsync(result, webResponse =>
				{
					ExtractResponseData(response, webResponse);
					ExecuteCallback(response, callback);
				});
			}
			catch(Exception ex)
			{
				ExecuteCallback(CreateErrorResponse(ex), callback);
			}
		}
开发者ID:BLesnau,项目名称:PixelPrinter,代码行数:24,代码来源:Http.Async.cs

示例2: DeleteService

        public HttpResponse DeleteService(string serviceName)
        {
            XmlNode serviceNode = xmlDoc.SelectSingleNode("ServiceConfig/Service[@Name='" + serviceName  + "']");
            XmlNode keyNode = xmlDoc.SelectSingleNode("ServiceConfig/ApiKeys/Key[@Name='" + serviceName + "']");

            if (serviceNode != null)
            {
                serviceNode.ParentNode.RemoveChild(serviceNode);                
            }

            if (keyNode != null)
            {
                apiKeysNode.RemoveChild(keyNode);
            }

            xmlDoc.Save(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Configs/ServiceConfig.xml")); 

            var res = new HttpResponse();
            res.StatusCode = HttpStatusCode.OK;
            return res; ;
        }
开发者ID:stauntonknight,项目名称:seqhack,代码行数:21,代码来源:ServicesController.cs

示例3: ExtractResponseData

        private static void ExtractResponseData(HttpResponse response, HttpWebResponse webResponse)
        {
            using (webResponse)
            {
            #if FRAMEWORK
                response.ContentEncoding = webResponse.ContentEncoding;
                response.Server = webResponse.Server;
            #endif
                response.ContentType = webResponse.ContentType;
                response.ContentLength = webResponse.ContentLength;
            #if WINDOWS_PHONE
                if (string.Equals(webResponse.Headers[HttpRequestHeader.ContentEncoding], "gzip", StringComparison.OrdinalIgnoreCase))
                    response.RawBytes = new GZipStream(webResponse.GetResponseStream()).ReadAsBytes();
                else
                    response.RawBytes = webResponse.GetResponseStream().ReadAsBytes();
            #else
                response.RawBytes = webResponse.GetResponseStream().ReadAsBytes();
            #endif
                //response.Content = GetString(response.RawBytes);
                response.StatusCode = webResponse.StatusCode;
                response.StatusDescription = webResponse.StatusDescription;
                response.ResponseUri = webResponse.ResponseUri;
                response.ResponseStatus = ResponseStatus.Completed;

                if (webResponse.Cookies != null)
                {
                    foreach (Cookie cookie in webResponse.Cookies)
                    {
                        response.Cookies.Add(new HttpCookie {
                            Comment = cookie.Comment,
                            CommentUri = cookie.CommentUri,
                            Discard = cookie.Discard,
                            Domain = cookie.Domain,
                            Expired = cookie.Expired,
                            Expires = cookie.Expires,
                            HttpOnly = cookie.HttpOnly,
                            Name = cookie.Name,
                            Path = cookie.Path,
                            Port = cookie.Port,
                            Secure = cookie.Secure,
                            TimeStamp = cookie.TimeStamp,
                            Value = cookie.Value,
                            Version = cookie.Version
                        });
                    }
                }

                foreach (var headerName in webResponse.Headers.AllKeys)
                {
                    var headerValue = webResponse.Headers[headerName];
                    response.Headers.Add(new HttpHeader { Name = headerName, Value = headerValue });
                }

                webResponse.Close();
            }
        }
开发者ID:beilharz,项目名称:RestSharp,代码行数:56,代码来源:Http.cs

示例4: RequestStreamCallback

		private void RequestStreamCallback(IAsyncResult result, Action<HttpResponse> callback)
		{
			var webRequest = (HttpWebRequest)result.AsyncState;

			if (_timeoutState.TimedOut)
			{
				var response = new HttpResponse {ResponseStatus = ResponseStatus.TimedOut};
				ExecuteCallback(response, callback);
				return;
			}

			// write body to request stream
			try
			{
				using(var requestStream = webRequest.EndGetRequestStream(result))
				{
					if(HasFiles || AlwaysMultipartFormData)
					{
						WriteMultipartFormData(requestStream);
					}
					else if (RequestBodyBytes != null)
					{
						requestStream.Write(RequestBodyBytes, 0, RequestBodyBytes.Length);
					}
					else
					{
						WriteStringTo(requestStream, RequestBody);
					}
				}
			}
			catch (Exception ex)
			{
				ExecuteCallback(CreateErrorResponse(ex), callback);
				return;
			}

			webRequest.BeginGetResponse(r => ResponseCallback(r, callback), webRequest);
		}
开发者ID:BLesnau,项目名称:PixelPrinter,代码行数:38,代码来源:Http.Async.cs

示例5: ConvertToRestResponse

		private RestResponse ConvertToRestResponse(IRestRequest request, HttpResponse httpResponse)
		{
			var restResponse = new RestResponse();
			restResponse.Content = httpResponse.Content;
			restResponse.ContentEncoding = httpResponse.ContentEncoding;
			restResponse.ContentLength = httpResponse.ContentLength;
			restResponse.ContentType = httpResponse.ContentType;
			restResponse.ErrorException = httpResponse.ErrorException;
			restResponse.ErrorMessage = httpResponse.ErrorMessage;
			restResponse.RawBytes = httpResponse.RawBytes;
			restResponse.ResponseStatus = httpResponse.ResponseStatus;
			restResponse.ResponseUri = httpResponse.ResponseUri;
			restResponse.Server = httpResponse.Server;
			restResponse.StatusCode = httpResponse.StatusCode;
			restResponse.StatusDescription = httpResponse.StatusDescription;
			restResponse.Request = request;

			foreach (var header in httpResponse.Headers)
			{
				restResponse.Headers.Add(new Parameter { Name = header.Name, Value = header.Value, Type = ParameterType.HttpHeader });
			}

			foreach (var cookie in httpResponse.Cookies)
			{
				restResponse.Cookies.Add(new RestResponseCookie {
					Comment = cookie.Comment,
					CommentUri = cookie.CommentUri,
					Discard = cookie.Discard,
					Domain = cookie.Domain,
					Expired = cookie.Expired,
					Expires = cookie.Expires,
					HttpOnly = cookie.HttpOnly,
					Name = cookie.Name,
					Path = cookie.Path,
					Port = cookie.Port,
					Secure = cookie.Secure,
					TimeStamp = cookie.TimeStamp,
					Value = cookie.Value,
					Version = cookie.Version
				});
			}

			return restResponse;
		}
开发者ID:jjoos,项目名称:RestSharp,代码行数:44,代码来源:RestClient.cs

示例6: ExtractResponseData

        private void ExtractResponseData(HttpResponse response, HttpWebResponse webResponse)
        {
            using (webResponse)
            {
#if FRAMEWORK
                response.ContentEncoding = webResponse.ContentEncoding;
                response.Server = webResponse.Server;
#endif
                response.ContentType = webResponse.ContentType;
                response.ContentLength = webResponse.ContentLength;

                Stream webResponseStream = webResponse.GetResponseStream();

#if WINDOWS_PHONE || UNITY
                string contentEncoding = "";
                if(webResponse.Headers[HttpResponseHeader.ContentEncoding] != null) { 
                    contentEncoding = webResponse.Headers[HttpResponseHeader.ContentEncoding];
                }
                    
                if (string.Equals(contentEncoding, "gzip", StringComparison.OrdinalIgnoreCase))
                {
                    GZipStream gzStream = new GZipStream(webResponseStream);

                    ProcessResponseStream(gzStream, response);
                }
                else if (string.Equals(contentEncoding, "deflate", StringComparison.OrdinalIgnoreCase))
                {
                    ZlibStream dfStream = new ZlibStream(webResponseStream);
                    
                    ProcessResponseStream(dfStream, response);
                }
                else
                { 
                    ProcessResponseStream(webResponseStream, response);
                }
#else
                this.ProcessResponseStream(webResponseStream, response);
#endif

                response.StatusCode = webResponse.StatusCode;
                response.StatusDescription = webResponse.StatusDescription;
                response.ResponseUri = webResponse.ResponseUri;
                response.ResponseStatus = ResponseStatus.Completed;

                if (webResponse.Cookies != null)
                {
                    foreach (Cookie cookie in webResponse.Cookies)
                    {
                        response.Cookies.Add(new HttpCookie
                                             {
                                                 Comment = cookie.Comment,
                                                 CommentUri = cookie.CommentUri,
                                                 Discard = cookie.Discard,
                                                 Domain = cookie.Domain,
                                                 Expired = cookie.Expired,
                                                 Expires = cookie.Expires,
                                                 HttpOnly = cookie.HttpOnly,
                                                 Name = cookie.Name,
                                                 Path = cookie.Path,
                                                 Port = cookie.Port,
                                                 Secure = cookie.Secure,
                                                 TimeStamp = cookie.TimeStamp,
                                                 Value = cookie.Value,
                                                 Version = cookie.Version
                                             });
                    }
                }

                foreach (string headerName in webResponse.Headers.AllKeys)
                {
                    string headerValue = webResponse.Headers[headerName];

                    response.Headers.Add(new HttpHeader
                                         {
                                             Name = headerName,
                                             Value = headerValue
                                         });
                }

                webResponse.Close();
            }
        }
开发者ID:eamonwoortman,项目名称:RestSharp.Unity,代码行数:82,代码来源:Http.cs

示例7: ResponseCallback

        private void ResponseCallback(IAsyncResult result, Action<HttpResponse> callback)
        {
            var response = new HttpResponse();
            response.ResponseStatus = ResponseStatus.None;

            try
            {
                if (timeoutState.TimedOut)
                {
                    response.ResponseStatus = ResponseStatus.TimedOut;
                    ExecuteCallback(response, callback);
                    return;
                }

                GetRawResponseAsync(result, webResponse =>
                {
                    ExtractResponseData(response, webResponse);
                    ExecuteCallback(response, callback);
                });
            }
            catch (Exception ex)
            {
                response.ErrorMessage = ex.Message;
                response.ErrorException = ex;
                response.ResponseStatus = ResponseStatus.Error;
                ExecuteCallback(response, callback);
            }
        }
开发者ID:philchuang,项目名称:DropNet,代码行数:28,代码来源:RestHttp.Async.cs

示例8: ExtractErrorResponse

        private void ExtractErrorResponse(HttpResponse httpResponse, Exception ex)
        {
            WebException webException = ex as WebException;

            if (webException != null && webException.Status == WebExceptionStatus.Timeout)
            {
                httpResponse.ResponseStatus = ResponseStatus.TimedOut;
                httpResponse.ErrorMessage = ex.Message;
                httpResponse.ErrorException = webException;

                return;
            }

            httpResponse.ErrorMessage = ex.Message;
            httpResponse.ErrorException = ex;
            httpResponse.ResponseStatus = ResponseStatus.Error;
        }
开发者ID:EduardKhudaiberdin,项目名称:RestSharp,代码行数:17,代码来源:Http.Sync.cs

示例9: GetStyleMethodInternalAsync

 private void GetStyleMethodInternalAsync(string method, Action<HttpResponse> callback)
 {
     try
     {
         var url = Url;
         var webRequest = ConfigureAsyncWebRequest(method, url);
         timeoutState = new TimeOutState { Request = webRequest };
         var asyncResult = webRequest.BeginGetResponse(result => ResponseCallback(result, callback), webRequest);
         SetTimeout(asyncResult, webRequest, timeoutState);
     }
     catch (Exception ex)
     {
         var response = new HttpResponse();
         response.ErrorMessage = ex.Message;
         response.ErrorException = ex;
         response.ResponseStatus = ResponseStatus.Error;
         ExecuteCallback(response, callback);
     }
 }
开发者ID:philchuang,项目名称:DropNet,代码行数:19,代码来源:RestHttp.Async.cs

示例10: PutPostInternalAsync

 private void PutPostInternalAsync(string method, Action<HttpResponse> callback)
 {
     try
     {
         var webRequest = ConfigureAsyncWebRequest(method, Url);
         PreparePostBody(webRequest);
         WriteRequestBodyAsync(webRequest, callback);
     }
     catch (Exception ex)
     {
         var response = new HttpResponse();
         response.ErrorMessage = ex.Message;
         response.ErrorException = ex;
         response.ResponseStatus = ResponseStatus.Error;
         ExecuteCallback(response, callback);
     }
 }
开发者ID:philchuang,项目名称:DropNet,代码行数:17,代码来源:RestHttp.Async.cs

示例11: GetRawResponseAsync

        private void GetRawResponseAsync(IAsyncResult result, Action<HttpWebResponse> callback)
        {
            var response = new HttpResponse();
            response.ResponseStatus = ResponseStatus.None;

            HttpWebResponse raw = null;

            try
            {
                var webRequest = (HttpWebRequest)result.AsyncState;
                raw = webRequest.EndGetResponse(result) as HttpWebResponse;
            }
            catch (WebException ex)
            {
                if (ex.Response is HttpWebResponse)
                {
                    raw = ex.Response as HttpWebResponse;
                }
            }

            callback(raw);
            raw.Close();
        }
开发者ID:philchuang,项目名称:DropNet,代码行数:23,代码来源:RestHttp.Async.cs

示例12: ExecuteCallback

 private void ExecuteCallback(HttpResponse response, Action<HttpResponse> callback)
 {
     #if WINDOWS_PHONE
     var dispatcher = Deployment.Current.Dispatcher;
     dispatcher.BeginInvoke(() =>
     {
     #endif
     callback(response);
     #if WINDOWS_PHONE
     });
     #endif
 }
开发者ID:philchuang,项目名称:DropNet,代码行数:12,代码来源:RestHttp.Async.cs

示例13: PerformGetResponse

        private HttpResponse PerformGetResponse(string method)
        {
            var response = new HttpResponse();
            response.ResponseStatus = ResponseStatus.None;

            try
            {
                Assert.InRange(CurrentCallNumber, 0, GetResponses.Count - 1);
                var r = GetResponses[CurrentCallNumber](method);
                CurrentCallNumber++;

                var bytes = r.Raw ? (byte[])r.ResponseObject : Encoding.UTF8.GetBytes(new BaseXmlSerializer().Serialize(r.ResponseObject));
                response.ResponseStatus = ResponseStatus.Completed;
                response.StatusCode = r.StatusCode;
                response.ContentType = r.ContentType ?? "text/xml";
                response.ContentLength = bytes.Length;
                response.RawBytes = bytes;
            }
            catch (Exception ex)
            {
                response.ErrorMessage = ex.Message;
                response.ErrorException = ex;
                response.ResponseStatus = ResponseStatus.Error;
            }

            Reset();

            return response;
        }
开发者ID:enkol,项目名称:IS24RestApi,代码行数:29,代码来源:HttpStub.cs

示例14: ExtractResponseData

		private void ExtractResponseData(HttpResponse response, HttpWebResponse webResponse)
		{
			using (webResponse)
			{
				response.ContentType = webResponse.ContentType;
				response.ContentLength = webResponse.ContentLength;
				Stream webResponseStream = webResponse.GetResponseStream();

				ProcessResponseStream(webResponseStream, response);
				response.StatusCode = webResponse.StatusCode;
				response.StatusDescription = webResponse.StatusDescription;
				response.ResponseUri = webResponse.ResponseUri;
				response.ResponseStatus = ResponseStatus.Completed;

				if (webResponse.Cookies != null)
				{
					foreach (Cookie cookie in webResponse.Cookies)
					{
						response.Cookies.Add(new HttpCookie {
							Comment = cookie.Comment,
							CommentUri = cookie.CommentUri,
							Discard = cookie.Discard,
							Domain = cookie.Domain,
							Expired = cookie.Expired,
							Expires = cookie.Expires,
							HttpOnly = cookie.HttpOnly,
							Name = cookie.Name,
							Path = cookie.Path,
							Port = cookie.Port,
							Secure = cookie.Secure,
							TimeStamp = cookie.TimeStamp,
							Value = cookie.Value,
							Version = cookie.Version
						});
					}
				}

				foreach (var headerName in webResponse.Headers.AllKeys)
				{
					var headerValue = webResponse.Headers[headerName];
					response.Headers.Add(new HttpHeader { Name = headerName, Value = headerValue });
				}

				webResponse.Close();
			}
		}
开发者ID:BLesnau,项目名称:PixelPrinter,代码行数:46,代码来源:Http.cs

示例15: GetResponse

        // stripped down version of rest-sharp implementation
        private HttpResponse GetResponse(WebRequest request)
        {
            var response = new HttpResponse { ResponseStatus = ResponseStatus.None };

            try
            {
                var webResponse = GetRawResponse(request);
                ExtractResponseData(response, webResponse);
            }
            catch (Exception ex)
            {
                response.ErrorMessage = ex.Message;
                response.ErrorException = ex;
                response.ResponseStatus = ResponseStatus.Error;
            }

            return response;
        }
开发者ID:jardrake03,项目名称:incert,代码行数:19,代码来源:FileProtocol.cs


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