本文整理汇总了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);
}
示例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;
}
}
}
示例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;
}
示例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;
}
示例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;
}
}
示例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);
}
}
示例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;
}
}
示例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;
}
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例15: XElementContent
public XElementContent(HttpContent content)
{
_Element = XElement.Load(content.ReadAsStreamAsync().Result);
}