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


C# HttpContent.ReadAsStreamAsync方法代码示例

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


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

示例1: GetResultAsync

 public static async Task<BerkeleyDtoResult> GetResultAsync(JsonSerializer serializer, HttpContent content)
 {
     using (Stream stream = await content.ReadAsStreamAsync().ConfigureAwait(false))
     using (var reader = new StreamReader(stream))
     using (var jsonReader = new JsonTextReader(reader))
         return serializer.Deserialize<BerkeleyDtoResult>(jsonReader);
 }
开发者ID:voronov-maxim,项目名称:BerkeleyDb,代码行数:7,代码来源:SerializeHelper.cs

示例2: ArgumentNullException

        HttpContent IHttpContentEncryptor.Encrypt(HttpContent originContent)
        {
            if (originContent == null)
            {
                throw new ArgumentNullException("originContent");
            }

            var originData = originContent.ReadAsStreamAsync().Result;

            if (originData.Length == 0)
            {
                return originContent;
            }

            this.algorithm.Key = this.keyProvider.Key;
            this.algorithm.IV = this.keyProvider.IV;

            using (var encryptor = algorithm.CreateEncryptor())
            {
                using (var encryptedData = new MemoryStream())
                {
                    var cryptoStream = new CryptoStream(encryptedData, encryptor, CryptoStreamMode.Write);
                    originData.CopyTo(cryptoStream);
                    cryptoStream.FlushFinalBlock();
                    encryptedData.Position = 0;

                    var encodedString = Convert.ToBase64String(encryptedData.ToArray());
                    var encryptedContent = new StringContent(encodedString);
                    encryptedContent.Headers.ContentType = originContent.Headers.ContentType;

                    return encryptedContent;
                }
            }
        }
开发者ID:jacktsai,项目名称:WebApiSurvey,代码行数:34,代码来源:AesHttpContentEncryptor.cs

示例3: readJsonIntoAddress

        private Location readJsonIntoAddress(HttpContent content)
        {
            DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(Response));
            Response bingResponse = jsonSerializer.ReadObject(content.ReadAsStreamAsync().Result) as Response;

            Location bingLocation = bingResponse.ResourceSets[0].Resources[0] as Location;

            return bingLocation;
        }
开发者ID:NaterTots,项目名称:TheBlueMarble,代码行数:9,代码来源:BingGeocoding.cs

示例4: ReadFromStreamAsync

 public override async Task<object> ReadFromStreamAsync(Type type,
                                                        Stream readStream,
                                                        HttpContent content,
                                                        IFormatterLogger formatterLogger,
                                                        CancellationToken cancellationToken)
 {
     var uf = new UploadedFile(StrHelper.UnquoteToken(content.Headers.ContentDisposition.FileName),
                               await content.ReadAsStreamAsync());
     return uf;
 }
开发者ID:riberk,项目名称:Rib.Common,代码行数:10,代码来源:StreramMediaTypeFormatter.cs

示例5: DecompressContent

        private static async Task<HttpContent> DecompressContent(HttpContent compressedContent, ICompressor compressor)
        {
            using (compressedContent)
            {
                MemoryStream decompressed = new MemoryStream();
                await compressor.Decompress(await compressedContent.ReadAsStreamAsync(), decompressed);
                var newContent = new StreamContent(decompressed);
                // copy content type so we know how to load correct formatter
                newContent.Headers.ContentType = compressedContent.Headers.ContentType;

                return newContent;
            }
        }
开发者ID:unipluss,项目名称:UniAlltid.Language,代码行数:13,代码来源:DecompressionHandler.cs

示例6: ConvertFromHttpContentAsync

		/// <inheritdoc />
		public async Task<object> ConvertFromHttpContentAsync(Type resultType, HttpContent httpContent, CancellationToken cancellationToken = default(CancellationToken))
		{
			if (!CanConvertFromHttpContent(resultType, httpContent))
			{
				throw new NotSupportedException("CanConvertFromHttpContent resulted in false, this is not supposed to be called.");
			}
			Log.Debug().WriteLine("Retrieving the content as XDocument, Content-Type: {0}", httpContent.Headers.ContentType);

			using (var contentStream = await httpContent.ReadAsStreamAsync().ConfigureAwait(false))
			{
				return XDocument.Load(contentStream);
			}
		}
开发者ID:dapplo,项目名称:Dapplo.HttpExtensions,代码行数:14,代码来源:XDocumentHttpContentConverter.cs

示例7: DecompressContentAsync

        private static async Task<HttpContent> DecompressContentAsync(HttpContent compressedContent, ICompressor compressor)
        {
            using (compressedContent)
            {
                var decompressed = new MemoryStream();
                await compressor.Decompress(await compressedContent.ReadAsStreamAsync(), decompressed).ConfigureAwait(true);

                decompressed.Position = 0;
                var newContent = new StreamContent(decompressed);

                newContent.Headers.ContentType = compressedContent.Headers.ContentType;
                return newContent;
            }
        }
开发者ID:oriches,项目名称:Simple.Rest,代码行数:14,代码来源:CompressionHandler.cs

示例8: DecompressContentAsync

        private static async Task<HttpContent> DecompressContentAsync(HttpContent compressedContent, ICompressor compressor)
        {
            using (compressedContent)
            {
                MemoryStream decompressed = new MemoryStream();
                await compressor.Decompress(await compressedContent.ReadAsStreamAsync(), decompressed).ConfigureAwait(false);
                
                // set position back to 0 so it can be read again
                decompressed.Position = 0;

                var newContent = new StreamContent(decompressed);
                // copy content type so we know how to load correct formatter
                newContent.Headers.ContentType = compressedContent.Headers.ContentType;
                return newContent;
            }
        }
开发者ID:isyedakhtar,项目名称:Fabrik.Common,代码行数:16,代码来源:DecompressionHandler.cs

示例9: DeserializeAsync

 public async Task<object> DeserializeAsync(Type type, HttpContent content) {
   HttpContentHeaders headers = content == null ? null : content.Headers;
   // If content length is 0 then return default value for this type
   if (headers != null) {
     if (headers.ContentLength == 0)
       return ReflectionHelper.GetDefaultValue(type);
     var mediaType = headers.ContentType.MediaType;
     Util.Check(_mediaTypes.Contains(mediaType), "JsonContentSerializer: cannot deserialize response body with content type {0}.", mediaType);
   }
   //Get stream
   var stream = await content.ReadAsStreamAsync();
   Encoding effectiveEncoding = SelectCharacterEncoding(headers);
   using (JsonTextReader jsonTextReader = new JsonTextReader(new StreamReader(stream, effectiveEncoding)) 
        { CloseInput = false, MaxDepth = _maxDepth }) {
     return _serializer.Deserialize(jsonTextReader, type);
   }
 }
开发者ID:yuanfei05,项目名称:vita,代码行数:17,代码来源:JsonContentSerializer.cs

示例10: Extract

        public static Object Extract( HttpContent content, Type commandType )
        {
            var read = content.ReadAsAsync( commandType );
            read.Wait();

            //reset the internal stream position to allow the WebAPI pipeline to read it again.
            content.ReadAsStreamAsync()
                .ContinueWith( t =>
                {
                    if( t.Result.CanSeek )
                    {
                        t.Result.Seek( 0, SeekOrigin.Begin );
                    }
                } )
                .Wait();

            return read.Result;
        }
开发者ID:RadicalFx,项目名称:Jason,代码行数:18,代码来源:JasonDelegatingHandler.cs

示例11: StoreImage

        public async Task<string> StoreImage(HttpContent content, string path, int advertId, string userId)
        {
            Stream stream = await content.ReadAsStreamAsync();
            string fileName = null;

            try
            {
                Image image = Image.FromStream(stream);
                var extension = ImageFormatUtils.FileExtensionFromEncoder(image.RawFormat);
                fileName = string.Format("{0}{1}{2}{3}{4}", advertId, userId, DateTime.Now.Ticks, random.Next() % 10000007, extension);
                var fullPath = Path.Combine(path, fileName);
                image.Save(fullPath);
            }
            catch
            {
                throw new InvalidDataException();
            }

            return fileName;
        }
开发者ID:kjifw,项目名称:CitizenService,代码行数:20,代码来源:ImagesService.cs

示例12: ArgumentNullException

        HttpContent IHttpContentEncryptor.Encrypt(HttpContent originContent)
        {
            if (originContent == null)
            {
                throw new ArgumentNullException("originContent");
            }

            var originStream = originContent.ReadAsStreamAsync().Result;

            if ( originStream.Length == 0)
            {
                return originContent;
            }

            byte[] originBytes = new byte[originStream.Length];
            originStream.Read(originBytes, 0, originBytes.Length);
            var encodedString = Convert.ToBase64String(originBytes);

            var encodedContent = new StringContent(encodedString);
            encodedContent.Headers.ContentType = originContent.Headers.ContentType;

            return encodedContent;
        }
开发者ID:jacktsai,项目名称:WebApiSurvey,代码行数:23,代码来源:FakeHttpContentEncryptor.cs

示例13: GetContentFromNet

        internal static async Task<rt.IHttpContent> GetContentFromNet(HttpContent content)
        {
            if (content == null)
                return null;

            var stream = await content.ReadAsStreamAsync().ConfigureAwait(false);
            var c = new rt.HttpStreamContent(stream.AsInputStream());

            CopyHeaders(content.Headers, c.Headers);

            return c;
        }
开发者ID:uwe-e,项目名称:BSE.Tunes,代码行数:12,代码来源:WinRtHttpClientHandler.cs

示例14: BufferRequestBodyAsync

 private static async Task BufferRequestBodyAsync(IOwinRequest owinRequest, HttpContent content)
 {
     await content.LoadIntoBufferAsync();
     // We need to replace the request body with a buffered stream so that other
     // components can read the stream
     owinRequest.Body = await content.ReadAsStreamAsync();
 }
开发者ID:khorchani,项目名称:aspnetwebstack,代码行数:7,代码来源:HttpMessageHandlerAdapter.cs

示例15: XElementContent

 public XElementContent(HttpContent content)
 {
     _Element = XElement.Load(content.ReadAsStreamAsync().Result);
 }
开发者ID:filipw,项目名称:RestAgent,代码行数:4,代码来源:HttpContentTests.cs


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