2

我 [认为我] 需要在 C# 中使用自定义字符集进行 base 64 编码,但我不知道如何。

具体来说,我正在尝试在 Unity3D 项目中使用 Mixpanel HTTP 规范 - https://mixpanel.com/docs/api-documentation/http-specification-insert-data。Mixpanel 说它具有 Base64 编码的自定义“风格”,实际上,当我使用允许我指定字符集的 Web 服务对相同的 JSON 进行编码时(http://www.motobit.com/util/base64-decoder -encoder.asp ),Mixpanel 报告成功。

(因此,我知道失败在于编码,而不是正在编码的数据)

4

2 回答 2

0

页面为 URL 提供的示例与 JSON 结构的示例不匹配。

这是一个工作示例:

var json = "{\"event\": \"game\", \"properties\": {\"ip\": \"123.123.123.123\", \"token\": \"e3bb4100330c35722740fb8c6f5abddc\", \"time\": 1245613885, \"action\": \"play\"}}";

var result = Convert.ToBase64String(Encoding.UTF8.GetBytes(json));

// result == "eyJldmVudCI6ICJnYW1lIiwgInByb3BlcnRpZXMiOiB7ImlwIjogIjEyMy4xMjMuMTIzLjEyMyIsICJ0b2tlbiI6ICJlM2JiNDEwMDMzMGMzNTcyMjc0MGZiOGM2ZjVhYmRkYyIsICJ0aW1lIjogMTI0NTYxMzg4NSwgImFjdGlvbiI6ICJwbGF5In19"
于 2013-02-03T00:30:03.987 回答
-1

Since it's encoding to Base64, but being used for web, it's custom set is based on that. See: C# Byte[] to Url Friendly String

Edit: Perhaps not... it seems they allow '+' and '/'. Strange.

于 2013-02-03T00:08:47.087 回答