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


C# HttpContent.ReadAsStringAsync方法代码示例

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


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

示例1: IsValid

        public static SchemaValidationResults IsValid(string rawSchema, HttpContent content)
        {
            if (content.Headers.ContentType == null || !content.Headers.ContentType.MediaType.Equals("application/json",
                StringComparison.InvariantCultureIgnoreCase))
            {
                return new SchemaValidationResults(true, new List<string>());
            }

            var readTask = content.ReadAsStringAsync().ConfigureAwait(false);
            var rawResponse = readTask.GetAwaiter().GetResult();

            return IsValidJSON(rawSchema, rawResponse);

        }
开发者ID:Kristinn-Stefansson,项目名称:raml-dotnet-tools,代码行数:14,代码来源:SchemaValidator.cs

示例2: ReadFromStreamAsync

 public override Task<object> ReadFromStreamAsync(Type type, System.IO.Stream readStream, HttpContent content, System.Net.Http.Formatting.IFormatterLogger formatterLogger)
 {
     var commandType = type;
     if (type.IsAbstract || type.IsInterface)
     {
         var commandContentType = content.Headers.ContentType.Parameters.FirstOrDefault(p => p.Name == "command");
         if (commandContentType != null)
         {
             commandType = GetCommandType(HttpUtility.UrlDecode(commandContentType.Value));
         }
         else
         {
             commandType = GetCommandType(HttpContext.Current.Request.Url.Segments.Last());
         }
     }
     var part = content.ReadAsStringAsync();
     var mediaType = content.Headers.ContentType.MediaType;
     return Task.Factory.StartNew<object>(() =>
     {
         object command = null;
         if (mediaType == "application/x-www-form-urlencoded" || mediaType == "application/command+form")
         {
             command = new FormDataCollection(part.Result).ConvertToObject(commandType);
         }
         if (command == null)
         {
             command = part.Result.ToJsonObject(commandType);
         }
         return command;
     });
 }
开发者ID:codeice,项目名称:IFramework,代码行数:31,代码来源:CommandMediaTypeFormatter.cs

示例3: ArgumentNullException

        HttpContent IHttpContentEncryptor.Decrypt(HttpContent encryptedContent)
        {
            if (encryptedContent == null)
            {
                throw new ArgumentNullException("encryptedContent");
            }

            var encodedString = encryptedContent.ReadAsStringAsync().Result;

            using (var encryptedData = new MemoryStream(Convert.FromBase64String(encodedString)))
            {
                if (encryptedData.Length == 0)
                {
                    return encryptedContent;
                }

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

                using (var decryptor = algorithm.CreateDecryptor())
                {
                    var cryptoStream = new CryptoStream(encryptedData, decryptor, CryptoStreamMode.Read);
                    var originData = new MemoryStream((int)encryptedData.Length);
                    cryptoStream.CopyTo(originData);
                    originData.Flush();
                    originData.Position = 0;

                    var originContent = new StreamContent(originData);
                    originContent.Headers.ContentType = encryptedContent.Headers.ContentType;

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

示例4: ValidateEntity

 private static void ValidateEntity(HttpContent content)
 {
     Assert.NotNull(content);
     Assert.Equal(ParserData.TextContentType, content.Headers.ContentType.ToString());
     string entity = content.ReadAsStringAsync().Result;
     Assert.Equal(ParserData.HttpMessageEntity, entity);
 }
开发者ID:haoduotnt,项目名称:aspnetwebstack,代码行数:7,代码来源:HttpContentMessageExtensionsTests.cs

示例5: ReadContentAsync

 private static string ReadContentAsync(HttpContent content)
 {
     Task task = content.LoadIntoBufferAsync();
     task.Wait(TimeoutConstant.DefaultTimeout);
     Assert.Equal(TaskStatus.RanToCompletion, task.Status);
     return content.ReadAsStringAsync().Result;
 }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:7,代码来源:HttpMessageContentTests.cs

示例6: VerifyResponse

 public static void VerifyResponse(HttpContent responseContent, string expected)
 {
     string response = responseContent.ReadAsStringAsync().Result;
     Regex updatedRegEx = new Regex("<updated>*.*</updated>");
     response = updatedRegEx.Replace(response, "<updated>UpdatedTime</updated>");
     Assert.Xml.Equal(expected, response);
 }
开发者ID:quentez,项目名称:aspnetwebstack,代码行数:7,代码来源:ODataTestUtil.cs

示例7: 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.");
			}
			return await httpContent.ReadAsStringAsync().ConfigureAwait(false);
		}
开发者ID:dapplo,项目名称:Dapplo.HttpExtensions,代码行数:9,代码来源:StringHttpContentConverter.cs

示例8: Act

 protected override void Act()
 {
     // Act
     using (DomainEvent.Disable())
         responseMessage = Client.GetAsync("http://temp.uri/api/registermatch").Result;
     httpContent = responseMessage.Content;
     content = httpContent.ReadAsStringAsync().Result;
 }
开发者ID:dlidstrom,项目名称:Snittlistan,代码行数:8,代码来源:RegisterMatch_Get.cs

示例9: GetResponseAsJObject

 public static async Task<JObject> GetResponseAsJObject(HttpContent response)
 {
     string rawContent = await response.ReadAsStringAsync();
     JObject json = JObject.Parse(rawContent);
     ResponseHelper.EnsureValidSyncResponse(json);
     Debug.WriteLine("Reponse returned:    {0}", json);
     return json;
 }
开发者ID:jlaanstra,项目名称:azure-mobile-services,代码行数:8,代码来源:ResponseHelper.cs

示例10: CacheResponse

        private void CacheResponse(HttpContent content)
        {
            var cachedResponse = new CachedResponse
            {
                Body = content.ReadAsStringAsync().Result,
                ContentType = content.Headers.ContentType.ToString()
            };

            OutputCacheAttribute.cache.Put(this.cacheKey, cachedResponse, this.timeout);
        }
开发者ID:peterhholroyd,项目名称:fmg_dhc,代码行数:10,代码来源:OutputCacheAttribute.cs

示例11: TransformSyncInsertResponse

        public static async Task<HttpContent> TransformSyncInsertResponse(HttpContent syncContent)
        {
            string rawContent = await syncContent.ReadAsStringAsync();
            JObject jobject = JObject.Parse(rawContent);
            EnsureValidSyncResponse(jobject);
            jobject.Remove("deleted");
            jobject.Remove("__version");

            return new StringContent(((JArray)jobject["results"]).First.ToString());
        }
开发者ID:jlaanstra,项目名称:azure-mobile-services,代码行数:10,代码来源:ResponseHelper.cs

示例12: IsValidAsync

        public static async Task<SchemaValidationResults> IsValidAsync(string rawSchema, HttpContent content)
        {
            if (content.Headers.ContentType == null || !content.Headers.ContentType.MediaType.Equals("application/json",
                StringComparison.InvariantCultureIgnoreCase))
            {
                return new SchemaValidationResults(true, new List<string>());
            }

            var rawContent = await content.ReadAsStringAsync();
            return IsValidJSON(rawSchema, rawContent);
        }
开发者ID:Kristinn-Stefansson,项目名称:raml-dotnet-tools,代码行数:11,代码来源:SchemaValidator.cs

示例13: SetContent

        /// <inheritdoc />
        /// <exception cref="System.ArgumentNullException">
        /// The <paramref name="content"/> parameter is <c>null</c>.
        /// </exception>
        protected internal override void SetContent(HttpContent content)
        {
            if (content == null)
            {
                throw new ArgumentNullException("content");
            }

            var result = content.ReadAsStringAsync().Result;

            _content = result;
        }
开发者ID:roryprimrose,项目名称:Headless,代码行数:15,代码来源:TextPage.cs

示例14: Rates

        /// <summary>
        /// Constructor.  Creates the Rates instance from the BitPay server response.
        /// </summary>
        /// <param name="response">The raw HTTP response from BitPay server api/rates call.</param>
        /// <param name="bp">bp - used to update self.</param>
        public Rates(HttpContent response, BitPay bp)
        {
            dynamic obj = Json.Decode(response.ReadAsStringAsync().Result);
            this._bp = bp;

            _rates = new List<Rate>();
            foreach (dynamic rateObj in obj)
            {
                _rates.Add(new Rate(rateObj.name, rateObj.code, rateObj.rate));
            }
        }
开发者ID:unChaz,项目名称:bitpay-csharp-api,代码行数:16,代码来源:Rates.cs

示例15: GetFormData

        private IEnumerable<KeyValuePair<string, string>> GetFormData(HttpContent content)
        {
            if (content is MultipartFormDataContent)
            {
                return ((MultipartFormDataContent)content)
                    .Where(CanProcessContent)
                    .SelectMany(GetFormData);
            }

            string rawFormData = content.ReadAsStringAsync().Result;

            return QueryStringMatcher.ParseQueryString(rawFormData);
        }
开发者ID:EdsonF,项目名称:mockhttp,代码行数:13,代码来源:FormDataMatcher.cs


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