Byte [] Array to String

Jam*_*ery 2 c#

我想将一个Byte []数组输出到一个字符串,以便我可以沿HTTPRequest发送它.可以吗?服务器是否会从中获取数据并创建文件?或者是否需要进行一些特殊编码?

该文件是图像.目前我有:

Byte[] fBuff = File.ReadAllBytes("C:/pic.jpeg");
Run Code Online (Sandbox Code Playgroud)

我需要把fBuff中的内容输出并输出它以发送请求.

Ale*_* LE 7

使用Convert.ToBase64String方法

Byte[] fBuff = File.ReadAllBytes("C:/pic.jpeg");
String base64 = Convert.ToBase64String(fBuff);
Run Code Online (Sandbox Code Playgroud)

这样,字符串就像posible一样紧凑,并且是将字节写入字符串并返回字节的"标准"方式.

要转换回字节,请使用Convert.FromBase64String:

String base64 = ""; // get the string
Byte[] fBuff = Convert.FromBase64String(base64);
Run Code Online (Sandbox Code Playgroud)