當前位置: 首頁>>代碼示例>>C#>>正文


C# Http.HttpResponse類代碼示例

本文整理匯總了C#中Microsoft.AspNet.Http.HttpResponse的典型用法代碼示例。如果您正苦於以下問題:C# HttpResponse類的具體用法?C# HttpResponse怎麽用?C# HttpResponse使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


HttpResponse類屬於Microsoft.AspNet.Http命名空間,在下文中一共展示了HttpResponse類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: WriteFileAsync

        /// <inheritdoc />
        protected override Task WriteFileAsync(HttpResponse response, CancellationToken cancellation)
        {
            var bufferingFeature = response.HttpContext.Features.Get<IHttpBufferingFeature>();
            bufferingFeature?.DisableResponseBuffering();

            return response.Body.WriteAsync(FileContents, 0, FileContents.Length, cancellation);
        }
開發者ID:4myBenefits,項目名稱:Mvc,代碼行數:8,代碼來源:FileContentResult.cs

示例2: WriteFileAsync

        /// <inheritdoc />
        protected override async Task WriteFileAsync(HttpResponse response)
        {
            if (!Path.IsPathRooted(FileName))
            {
                throw new NotSupportedException(Resources.FormatFileResult_PathNotRooted(FileName));
            }

            var sendFile = response.HttpContext.Features.Get<IHttpSendFileFeature>();
            if (sendFile != null)
            {
                await sendFile.SendFileAsync(
                    FileName,
                    offset: 0,
                    length: null,
                    cancellation: default(CancellationToken));
            }
            else
            {
                var fileStream = GetFileStream(FileName);

                using (fileStream)
                {
                    await fileStream.CopyToAsync(response.Body, DefaultBufferSize);
                }
            }
        }
開發者ID:phinq19,項目名稱:git_example,代碼行數:27,代碼來源:PhysicalFileResult.cs

示例3: ToHttpResponse

        internal static HttpResponsePacket ToHttpResponse(HttpResponse response, ServiceMessage msg)
        {
            var rsp = new HttpResponsePacket();

            foreach (var hdr in response.Headers)
            {
                // TODO: Fix adding response headers
                //AddHttpHeader(hdr);
            }

            //TODO: Decide if to read mostly from ServiceMessage or from response.

            //rsp.Version = response.... //TODO: Add a default version here
            rsp.StatusCode = (int)response.StatusCode;
            rsp.StatusDescription = ((IHttpResponseFeature)msg).ReasonPhrase;

            if (response.Body != null)
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    response.Body.Position = 0;
                    response.Body.CopyTo(ms);
                    rsp.Content = ms.ToArray();
                }
            }

            return rsp;
        }
開發者ID:BrisWhite,項目名稱:RestBus,代碼行數:28,代碼來源:MessageHelpers.cs

示例4: WriteFileAsync

        /// <inheritdoc />
        protected override Task WriteFileAsync(HttpResponse response)
        {
            var bufferingFeature = response.HttpContext.Features.Get<IHttpBufferingFeature>();
            bufferingFeature?.DisableResponseBuffering();

            return response.Body.WriteAsync(FileContents, offset: 0, count: FileContents.Length);
        }
開發者ID:phinq19,項目名稱:git_example,代碼行數:8,代碼來源:FileContentResult.cs

示例5: WriteFileAsync

        /// <inheritdoc />
        protected override async Task WriteFileAsync(HttpResponse response, CancellationToken cancellation)
        {
            if (!Path.IsPathRooted(FileName))
            {
                throw new FileNotFoundException(Resources.FormatFileResult_InvalidPath(FileName), FileName);
            }

            var sendFile = response.HttpContext.Features.Get<IHttpSendFileFeature>();
            if (sendFile != null)
            {
                await sendFile.SendFileAsync(
                    FileName,
                    offset: 0,
                    length: null,
                    cancellation: cancellation);

                return;
            }
            else
            {
                var fileStream = GetFileStream(FileName);

                using (fileStream)
                {
                    await fileStream.CopyToAsync(response.Body, DefaultBufferSize, cancellation);
                }

                return;
            }
        }
開發者ID:4myBenefits,項目名稱:Mvc,代碼行數:31,代碼來源:PhysicalFileProviderResult.cs

示例6: WriteFileAsync

        /// <inheritdoc />
        protected async override Task WriteFileAsync(HttpResponse response, CancellationToken cancellation)
        {
            var outputStream = response.Body;

            using (FileStream)
            {
                await FileStream.CopyToAsync(outputStream, BufferSize, cancellation);
            }
        }
開發者ID:AndersBillLinden,項目名稱:Mvc,代碼行數:10,代碼來源:FileStreamResult.cs

示例7: SetCacheHeaders

 private void SetCacheHeaders(HttpResponse response)
 {
     if (_options.CacheLength != null)
     {
         var expires = DateTime.Now.AddSeconds(_options.CacheLength.TotalSeconds);
         response.Headers.SetCommaSeparatedValues("Cache-Control", "public", $"max-age={_options.CacheLength.TotalSeconds}");
         response.Headers.Set("Expires", expires.ToUniversalTime().ToString("R"));
     }
 }
開發者ID:luckycadow,項目名稱:beerfish,代碼行數:9,代碼來源:AssetMiddleware.cs

示例8: RespondWithSwaggerJson

        private void RespondWithSwaggerJson(HttpResponse response, SwaggerDocument swagger)
        {
            response.StatusCode = 200;
            response.ContentType = "application/json";

            using (var writer = new StreamWriter(response.Body))
            {
                _swaggerSerializer.Serialize(writer, swagger);
            }
        }
開發者ID:serkanpektas,項目名稱:Ahoy,代碼行數:10,代碼來源:SwaggerDocsMIddleware.cs

示例9: SerializeResponseObject

 private void SerializeResponseObject(HttpResponse response, object value)
 {
     using (var writer = new StreamWriter(response.Body))
     {
         using (var jsonWriter = new JsonTextWriter(writer))
         {
             jsonWriter.CloseOutput = false;
             var jsonSerializer = JsonSerializer.Create(/*TODO: SerializerSettings*/);
             jsonSerializer.Serialize(jsonWriter, value);
         }
     }
 }
開發者ID:robbert229,項目名稱:omnisharp-roslyn,代碼行數:12,代碼來源:StatusMiddleware.cs

示例10: WriteFileAsync

        /// <inheritdoc />
        protected async override Task WriteFileAsync(HttpResponse response, CancellationToken cancellation)
        {
            var outputStream = response.Body;

            using (FileStream)
            {
                var bufferingFeature = response.HttpContext.Features.Get<IHttpBufferingFeature>();
                bufferingFeature?.DisableResponseBuffering();

                await FileStream.CopyToAsync(outputStream, BufferSize, cancellation);
            }
        }
開發者ID:4myBenefits,項目名稱:Mvc,代碼行數:13,代碼來源:FileStreamResult.cs

示例11: WriteResponseBodyAsync

 internal static Task WriteResponseBodyAsync(HttpResponse response, string uid, DateTimeOffset? datetime, TimeSpan? duration, string summary, string description, string location) {
     return response.WriteAsync(
         "BEGIN:VCALENDAR\r\n" +
         "VERSION:2.0\r\n" +
         "BEGIN:VEVENT\r\n" +
         "UID:" + uid + "\r\n" +
         "DTSTART:" + datetime?.ToString(DateTimeFormat) + "\r\n" +
         "DTEND:" + datetime?.Add(duration ?? TimeSpan.Zero).ToString(DateTimeFormat) + "\r\n" +
         "SUMMARY:" + summary + "\r\n" +
         "DESCRIPTION:" + description + "\r\n" +
         "LOCATION:" + location +
         "END:VEVENT\r\n" +
         "END:VCALENDAR\r\n");
 }
開發者ID:migrap,項目名稱:Migrap.AspNet.Mvc.Formatters.iCalendar,代碼行數:14,代碼來源:iCalendarOutputFormatter.cs

示例12: AddLocationHeaderToMapping

        public static void AddLocationHeaderToMapping(
            HttpResponse response,
            IDictionary<string, string> contentIdToLocationMapping,
            string contentId)
        {
            //Contract.Assert(response != null);
            //Contract.Assert(contentIdToLocationMapping != null);
            //Contract.Assert(contentId != null);

            //if (response.Headers.Location != null)
            //{
            //    contentIdToLocationMapping.Add(contentId, response.Headers.Location.AbsoluteUri);
            //}
            throw new NotImplementedException("AddLocationHeaderToMapping");
        }
開發者ID:akrisiun,項目名稱:WebApi,代碼行數:15,代碼來源:ContentIdHelpers.cs

示例13: WriteOutput

		public static async Task WriteOutput(HttpResponse Response, string Title, Head.Tag[] HeadTags, string Body) {
			var sb = new StringBuilder();
			sb.Append("<!DOCTYPE html><head><meta charset=\"utf-8\">");
			if (Title != null) {
				sb.Append("<title>" + Title + "</title>");
			}
			if (HeadTags != null) {
				foreach (var a in HeadTags) {
					sb.Append(a.Output());
				}
			}
			sb.Append("</head><body>");
			sb.Append(Body);
			sb.Append("</body></html>");
			await Response.WriteAsync(sb.ToString());
		}
開發者ID:matthewhancock,項目名稱:plasticbagfreeportsmouth,代碼行數:16,代碼來源:Html.cs

示例14: WriteFileAsync

        /// <inheritdoc />
        protected override Task WriteFileAsync(HttpResponse response, CancellationToken cancellation)
        {
            var fileProvider = GetFileProvider(response.HttpContext.RequestServices);

            var resolveFilePathResult = ResolveFilePath(fileProvider);

            if (resolveFilePathResult.PhysicalFilePath != null)
            {
                return CopyPhysicalFileToResponseAsync(response, resolveFilePathResult.PhysicalFilePath, cancellation);
            }
            else
            {
                // Example: An embedded resource
                var sourceStream = resolveFilePathResult.FileInfo.CreateReadStream();
                return CopyStreamToResponseAsync(sourceStream, response, cancellation);
            }
        }
開發者ID:njannink,項目名稱:sonarlint-vs,代碼行數:18,代碼來源:FilePathResult.cs

示例15: CreateMockActionContext

        private static ActionContext CreateMockActionContext(
                                                             HttpResponse response = null,
                                                             string requestAcceptHeader = "application/*",
                                                             string requestContentType = "application/json",
                                                             string requestAcceptCharsetHeader = "",
                                                             bool respectBrowserAcceptHeader = false)
        {
            var httpContext = new Mock<HttpContext>();
            if (response != null)
            {
                httpContext.Setup(o => o.Response).Returns(response);
            }

            var content = "{name: 'Person Name', Age: 'not-an-age'}";
            var contentBytes = Encoding.UTF8.GetBytes(content);

            var request = new DefaultHttpContext().Request;
            request.Headers["Accept-Charset"] = requestAcceptCharsetHeader;
            request.Headers["Accept"] = requestAcceptHeader;
            request.ContentType = requestContentType;
            request.Body = new MemoryStream(contentBytes);

            httpContext.Setup(o => o.Request).Returns(request);
            httpContext.Setup(o => o.RequestServices).Returns(GetServiceProvider());
            var optionsAccessor = new MockMvcOptionsAccessor();
            optionsAccessor.Options.OutputFormatters.Add(new StringOutputFormatter());
            optionsAccessor.Options.OutputFormatters.Add(new JsonOutputFormatter());
            optionsAccessor.Options.RespectBrowserAcceptHeader = respectBrowserAcceptHeader;
            var mockContextAccessor = new Mock<IScopedInstance<ActionBindingContext>>();
            mockContextAccessor
                .SetupGet(o => o.Value)
                .Returns(new ActionBindingContext()
                {
                    OutputFormatters = optionsAccessor.Options.OutputFormatters
                });

            httpContext.Setup(o => o.RequestServices.GetService(typeof(IScopedInstance<ActionBindingContext>)))
                       .Returns(mockContextAccessor.Object);
            httpContext.Setup(o => o.RequestServices.GetService(typeof(IOptions<MvcOptions>)))
                .Returns(optionsAccessor);
            httpContext.Setup(o => o.RequestServices.GetService(typeof(ILogger<ObjectResult>)))
                .Returns(new Mock<ILogger<ObjectResult>>().Object);

            return new ActionContext(httpContext.Object, new RouteData(), new ActionDescriptor());
        }
開發者ID:RehanSaeed,項目名稱:Mvc,代碼行數:45,代碼來源:HttpNotFoundObjectResultTest.cs


注:本文中的Microsoft.AspNet.Http.HttpResponse類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。