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


C# ByteArrayContent.ReadAsStringAsync方法代码示例

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


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

示例1: UsingByteArrayContent

        public static void UsingByteArrayContent()
        {
            // ByteArrayContent is hardly different than StringContent,
            // but it can be more convenient for lower-level operations
            // when bytes are already available (as opposed to using a Stream).
            var bytes = Encoding.ASCII.GetBytes(Helpers.__);
            var content = new ByteArrayContent(bytes); // This also takes offset and limit parameters.

            var body = content.ReadAsStringAsync().Result;

            Helpers.AssertEquality("Hello, bytes!", body);
        }
开发者ID:sara62,项目名称:WebApiKoans,代码行数:12,代码来源:AboutContent.cs

示例2: ReadAsMultipartAsync_NestedMultipartContent

        public void ReadAsMultipartAsync_NestedMultipartContent(string boundary)
        {
            const int nesting = 10;
            const string innerText = "Content";

            MultipartContent innerContent = new MultipartContent("mixed", boundary);
            innerContent.Add(new StringContent(innerText));
            for (var cnt = 0; cnt < nesting; cnt++)
            {
                string outerBoundary = String.Format("{0}_{1}", boundary, cnt);
                MultipartContent outerContent = new MultipartContent("mixed", outerBoundary);
                outerContent.Add(innerContent);
                innerContent = outerContent;
            }

            MemoryStream memStream = new MemoryStream();
            innerContent.CopyToAsync(memStream).Wait();
            memStream.Position = 0;
            byte[] data = memStream.ToArray();
            HttpContent content = new ByteArrayContent(data);
            content.Headers.ContentType = innerContent.Headers.ContentType;

            for (var cnt = 0; cnt < nesting + 1; cnt++)
            {
                MultipartMemoryStreamProvider result = content.ReadAsMultipartAsync().Result;
                Assert.Equal(1, result.Contents.Count);
                content = result.Contents[0];
                Assert.NotNull(content);
            }

            string text = content.ReadAsStringAsync().Result;
            Assert.Equal(innerText, text);
        }
开发者ID:RhysC,项目名称:aspnetwebstack,代码行数:33,代码来源:HttpContentMultipartExtensionsTests.cs

示例3: ReadAsStringAsync

        public void ReadAsStringAsync()
        {
            byte[] b = { 77, 55 };

            var sc = new ByteArrayContent (b);
            var res = sc.ReadAsStringAsync ().Result;
            Assert.AreEqual ("M7", res, "#1");
        }
开发者ID:RainsSoft,项目名称:dotnet-httpclient35,代码行数:8,代码来源:ByteArrayContentTest.cs

示例4: Decrypt

        public HttpRequestMessage Decrypt(HttpRequestMessage cipherRequest)
        {
            if (cipherRequest == null)
            {
                throw new ArgumentNullException("cipherRequest");
            }

            var cipherContent = cipherRequest.Content;
            byte[] plain;
            try
            {
                if (cipherContent == null)
                {
                    throw new HttpContentNullException();
                }

                var cipherModel = cipherContent.ReadAsAsync<JObject>().Result;

                string timestamp;
                byte[] cipher;
                string signature;
                this.ParseCipherModel(cipherModel, out timestamp, out cipher, out signature);
                this.timestampProvider.Validate(timestamp);
                this.Decrypt(cipher, timestamp, signature, out plain);

                this.lastTimestamp = timestamp; // keep timestamp for decrypting response.
            }
            catch (Exception ex)
            {
                throw new InvalidHttpMessageException(ex);
            }

            if (DefaultHttpMessageCryptoService.IsEmptyContent(plain))
            {
                Trace.TraceWarning("Content of request is ALTERNATIVES, replace to NULL!");
                cipherRequest.Content = null;
            }
            else
            {
                var decryptedContent = new ByteArrayContent(plain);
                Trace.TraceInformation("Decrypted request content: {0}", decryptedContent.ReadAsStringAsync().Result);

                cipherRequest.Content = decryptedContent;
                cipherRequest.Content.Headers.ContentType = cipherContent.Headers.ContentType;
            }

            return cipherRequest;
        }
开发者ID:jacktsai,项目名称:ApiFoundation,代码行数:48,代码来源:DefaultHttpMessageCryptoService.cs

示例5: ReadAsMultipartAsyncNestedMultipartContentAsync

        public void ReadAsMultipartAsyncNestedMultipartContentAsync(string boundary)
        {
            const int nesting = 10;
            const string innerText = "Content";

            MultipartContent innerContent = new MultipartContent("mixed", boundary);
            innerContent.Add(new StringContent(innerText));
            for (var cnt = 0; cnt < nesting; cnt++)
            {
                string outerBoundary = String.Format("{0}_{1}", boundary, cnt);
                MultipartContent outerContent = new MultipartContent("mixed", outerBoundary);
                outerContent.Add(innerContent);
                innerContent = outerContent;
            }

            MemoryStream memStream = new MemoryStream();
            innerContent.CopyToAsync(memStream).Wait();
            memStream.Position = 0;
            byte[] data = memStream.ToArray();
            HttpContent content = new ByteArrayContent(data);
            content.Headers.ContentType = innerContent.Headers.ContentType;

            for (var cnt = 0; cnt < nesting + 1; cnt++)
            {
                Task<IEnumerable<HttpContent>> task = content.ReadAsMultipartAsync();
                task.Wait(TimeoutConstant.DefaultTimeout);
                IEnumerable<HttpContent> result = task.Result;
                Assert.Equal(1, result.Count());
                content = result.ElementAt(0);
                Assert.NotNull(content);
            }

            string text = content.ReadAsStringAsync().Result;
            Assert.Equal(innerText, text);
        }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:35,代码来源:HttpContentMultipartExtensionsTests.cs


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