本文整理汇总了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);
}
示例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;
});
}
示例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;
}
}
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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());
}
示例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);
}
示例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;
}
示例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));
}
}
示例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);
}