C# 如何 response.write bytearray?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/629675/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 11:00:22  来源:igfitidea点击:

how to response.write bytearray?

c#asp.net

提问by Tom

This is not working:

这不起作用:

byte[] tgtBytes = ...

Response.Write(tgtBytes);

采纳答案by Andrew Barrett

You're probably looking for:

您可能正在寻找:

Response.BinaryWrite(tgtBytes);

MSDN documentation here.

MSDN 文档在这里

回答by Dead account

If you want to output hex values

如果要输出十六进制值

byte[] tgtBytes = ...
foreach (byte b in tgtBytes)
    Response.Write("{0:2x}", b);

Or do you want to do;

或者你想做什么;

Response.Write(System.Text.Encoding.ASCII.GetString(tgtBytes));

To convert the bytes to ASCII text and output a string.

将字节转换为 ASCII 文本并输出字符串。

回答by Fabian Vilers

Response.OutputStream.Write(tgtBytes, 0, tgtBytes.Length);