本文整理汇总了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);
}
示例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);
}
示例3: ReadAsStringAsync
public void ReadAsStringAsync()
{
byte[] b = { 77, 55 };
var sc = new ByteArrayContent (b);
var res = sc.ReadAsStringAsync ().Result;
Assert.AreEqual ("M7", res, "#1");
}
示例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;
}
示例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);
}