Java 通过REST POST方法发送附件时,C#中的Base64编码问题
在C#/Xamarin中是否可以像在Java中一样将字节数组编码为Base64Java 通过REST POST方法发送附件时,C#中的Base64编码问题,java,c#,xamarin,base64,Java,C#,Xamarin,Base64,在C#/Xamarin中是否可以像在Java中一样将字节数组编码为Base64 byte[]encBytes=Base64.encodeBase64(缓冲区) 因此,我不想在Base64字符串中转换字节,我想在Java中使用Base64编码的字节数组 编辑以反映答案: byte[] buffer = new byte[(int)fileLen]; int offset = 0;int numRead = 0; while ( offset < buffer.length &&a
byte[]encBytes=Base64.encodeBase64(缓冲区)代码>
因此,我不想在Base64字符串中转换字节,我想在Java中使用Base64编码的字节数组
编辑以反映答案:
byte[] buffer = new byte[(int)fileLen];
int offset = 0;int numRead = 0;
while ( offset < buffer.length && ( numRead = input.read(buffer, offset, buffer.length - offset)) >= 0)
{
offset += numRead;
}
byte[] encBytes = Base64.encodeBase64(buffer);
byte[]buffer=新字节[(int)fileLen];
整数偏移=0;int numRead=0;
而(偏移量=0)
{
偏移量+=numRead;
}
字节[]encBytes=Base64.encodeBase64(缓冲区);
因此,缓冲区由文件中的数据填充,然后编码为base64。
我看不到一种从源代码读取文件的方法,就像在那个snipet中一样。
编辑2:
问题似乎不仅仅是编码,而是将编码文件发送到服务器。
发送文件时,它会在服务器上创建一个文件,但该文件已损坏(pdf和excel)或为空(docx)。与java中的类似
public static String toBase64(String value){
byte[] message = value.getBytes("UTF-8");
}
在C中#
但有了这个,我又得到了Base64字符串,而不是一个字节。
byte[] array = UTF8Encoding.UTF8.GetBytes(value);
string base64 =Convert.FromBase64String(array);