经典的ASP Base64编码和换行符

时间:2019-01-27 23:25:41

标签: vbscript asp-classic adodb

此答案中我一直在使用base64编码功能(代码在下面)

https://stackoverflow.com/a/506992/510296

我注意到它在第72个字符之后包装了输出行(当我尝试将编码后的字符串传递给eBay API时,这会导致问题)。

我可以使用replace(base64string, vblf, "")轻松地删除换行符,但想询问是否有防止输出换行符的适当方法。

Function Base64Encode(sText)
    Dim oXML, oNode
    Set oXML = CreateObject("Msxml2.DOMDocument.3.0")
    Set oNode = oXML.CreateElement("base64")
    oNode.dataType = "bin.base64"
    oNode.nodeTypedValue =Stream_StringToBinary(sText)
    Base64Encode = oNode.text
    Set oNode = Nothing
    Set oXML = Nothing
End Function

Function Stream_StringToBinary(Text)
    Const adTypeText = 2
    Const adTypeBinary = 1

    'Create Stream object
    Dim BinaryStream 'As New Stream
    Set BinaryStream = CreateObject("ADODB.Stream")

    'Specify stream type - we want To save text/string data.
    BinaryStream.Type = adTypeText

    'Specify charset For the source text (unicode) data.
    BinaryStream.CharSet = "us-ascii"

    'Open the stream And write text/string data To the object
    BinaryStream.Open
    BinaryStream.WriteText Text

    'Change stream type To binary
    BinaryStream.Position = 0
    BinaryStream.Type = adTypeBinary

    'Ignore first two bytes - sign of
    BinaryStream.Position = 0

    'Open the stream And get binary data from the object
    Stream_StringToBinary = BinaryStream.Read

    Set BinaryStream = Nothing
End Function

0 个答案:

没有答案