我遇到了将文件写入响应对象的问题。该文件是Base64编码的,并通过Web服务发送到ASP代码。
dim contentType, fileName
filename = request("FileName")
contentType = request("ContentType")
If Not Response.isClientConnected Then
Response.end
End If
Response.buffer = true
Response.Clear
Response.Addheader "Content-Disposition", "attachment; filename=" & filename
Response.contenttype = contentType
dim oSoapClient
Set oSoapClient = Server.CreateObject("MSSOAP.SoapClient")
oSoapClient.ClientProperty("ServerHTTPRequest") = True
oSoapClient.mssoapinit "http://myWS/test.asmx?WSDL"
dim sRequest, sResponse
sRequest = "<Root><Attachment id=""" & Request("ID") & """/></Root>"
sResponse = oSoapClient.GetAttachment(sRequest)
Dim oXML: Set oXML = LoadXMLString(sResponse)
Dim oAttachment
set oAttachment = oXML.SelectSingleNode("/Root/Attachment")
if not oAttachment is nothing then
Response.Binarywrite(Base64Decode(oAttachment.attributes.getNamedItem("BinaryData").value))
End if
Response.End
BinaryWrite每隔一个字节添加额外的空字符。将其更改为response.write并且它不会放置空值,但如果找到空字符则终止字符串。
我正在寻找一种方法来使用binarywrite而不添加额外的空值。这是一个字符集问题吗?
由于
答案 0 :(得分:0)
BinaryWrite在这里做的正确。 Base64Decode 功能的返回类型是什么?每个字节之间的额外空字符是不正确处理UTF-16 / UCS-16 unicode数据的症状。
理想情况下,您应该将VARIANT发送到BinaryWrite,它表示公开IStream的对象或SAFEARRAY。如果发送一个字符串的VARIANT,它将被BinaryWrite作为BSTR接收,它是16位宽,并且对于英语/拉丁字符集数据,每隔一个字节将显示空/零。