如何在Scala中将字节数组放入XML
我正在与一个.NETWeb服务交互。根据服务描述,服务器需要base64Binary类型 这就是我试图构建SOAP数据包的方式:如何在Scala中将字节数组放入XML,scala,cordova,finagle,Scala,Cordova,Finagle,我正在与一个.NETWeb服务交互。根据服务描述,服务器需要base64Binary类型 这就是我试图构建SOAP数据包的方式: <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
</soap:Header>
<soap:Body>
<uploadFile xmlns="http://localhost/">
<FileDetails>
<ReferenceNumber>123</ReferenceNumber>
<FileName>testfile</FileName>
<FullFilePath>file</FullFilePath>
<FileType>1</FileType>
<FileContents>{request.getContent().array()}</FileContents>
</FileDetails>
</uploadFile>
</soap:Body>
</soap:Envelope>
123
测试文件
文件
1.
{request.getContent().array()}
在上面的代码片段中,request.getContent().array()是我从PhoneGap开发的移动应用程序收到的HTTP请求
服务器响应文件内容无效。有什么想法吗?您当前的版本只是将字节(我假设
request.getContent().array()
是一个字节数组)写入以空格分隔的10进制整数:
scala> val bytes = 1 to 10 map(_.toByte) toArray
bytes: Array[Byte] = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
scala> <FileContents>{bytes}</FileContents>
res0: scala.xml.Elem = <FileContents>1 2 3 4 5 6 7 8 9 10</FileContents>
您可能需要稍微修改一下选项,但这更可能是您所需要的。您当前的版本只是将字节(我假设
request.getContent().array()
是一个字节数组)写入以空格分隔的10进制整数:
scala> val bytes = 1 to 10 map(_.toByte) toArray
bytes: Array[Byte] = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
scala> <FileContents>{bytes}</FileContents>
res0: scala.xml.Elem = <FileContents>1 2 3 4 5 6 7 8 9 10</FileContents>
您可能需要稍微修改一下选项,但这更可能是您所需要的。我太傻了(为我辩护,今天是星期五;-)。谢谢你的解决方案。你是个救命恩人,特拉维斯。我真傻(为我辩护——那天是星期五;-)。谢谢你的解决方案。特拉维斯,你是个救生员。