[英]Decoding a base64 string from windows phone
我收到一個包含base64字符串的Soap響應。 我正在使用XDocument獲取元素的值和類似這樣的函數來讀取它
public void main()
{
//****UPDATE
string data64 = "";
data64 = removeNewLinesFromString(data64);
content = data64.ToCharArray();
byte[] binaryData = Convert.FromBase64CharArray(content, 0, content.Length);
Stream stream = new MemoryStream(binaryData);
BinaryReader reader = new BinaryReader(stream,Encoding.UTF8);
string object64 = SoapSerializable.ReadUTF(reader);
}
這是readUTF函數
public static String ReadUTF(BinaryReader reader)
{
// read the following string's length in bytes
int length = Helpers.FlipInt32(reader.ReadInt32());
// read the string's data bytes
byte[] utfString = reader.ReadBytes(length);
// get the string by interpreting the read data as UTF-8
return System.Text.Encoding.UTF8.GetString(utfString, 0, utfString.Length);
}
和我的FlipInt32函數
public static Int32 FlipInt32(Int32 value)
{
Int32 a = (value >> 24) & 0xFF;
Int32 b = (value >> 16) & 0xFF;
Int32 c = (value >> 8) & 0xFF;
Int32 d = (value >> 0) & 0xFF;
return (((((d << 8) | c) << 8) | b) << 8) | a;
}
但是結果值與在線解碼器給出的結果略有不同。
我在這里想念什么嗎?
我不確定您要使用BinaryReader
做什么,但是我要做的this is a dummy encoded base64 string
從您的base64數據中得到this is a dummy encoded base64 string
string data64 = "dGhpcyBpcyBhIGR1bW15IGVuY29kZWQgYmFzZTY0IHN0cmluZy4=";
var buf = Convert.FromBase64String(data64);
var str = Encoding.UTF8.GetString(buf);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.