Powershell Base64 字符串转字节
Powershell Base64 String to Bytes
我正在尝试使用 Powershell 将文件转换为 Web 服务所需的 Base64 编码字节数组。我该怎么做?
我目前的做法是:
$content = [System.IO.File]::ReadAllBytes("$scriptpath/dummy.txt")
$base64String =[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($content))
$proxy = New-WebServiceProxy -Uri _____.wsdl
//... set up proxy-objects
$namespace = $proxy.GetType().Namespace
$soapObject= new-object ("$namespace.customType")
$soapObject.byteArray = base64String
最后一行不起作用,因为 base64String 不是字节数组。不幸的是,我需要成为一个字节数组,我无法访问服务器端。
使用 XML-Notation 我可以直接将 Base64Encoded 字符串放入。但是powershell怎么办呢?
<customType><byteArray>anyBase64String</byteArray></customType>
如果 soapObject.byteArray
需要字节数组,我希望能够将数组提供给它 - 让代理在 base64 中执行编码。所以:
$soapObject.byteArray = content
根本不需要base64String
。
我正在尝试使用 Powershell 将文件转换为 Web 服务所需的 Base64 编码字节数组。我该怎么做?
我目前的做法是:
$content = [System.IO.File]::ReadAllBytes("$scriptpath/dummy.txt")
$base64String =[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($content))
$proxy = New-WebServiceProxy -Uri _____.wsdl
//... set up proxy-objects
$namespace = $proxy.GetType().Namespace
$soapObject= new-object ("$namespace.customType")
$soapObject.byteArray = base64String
最后一行不起作用,因为 base64String 不是字节数组。不幸的是,我需要成为一个字节数组,我无法访问服务器端。
使用 XML-Notation 我可以直接将 Base64Encoded 字符串放入。但是powershell怎么办呢?
<customType><byteArray>anyBase64String</byteArray></customType>
如果 soapObject.byteArray
需要字节数组,我希望能够将数组提供给它 - 让代理在 base64 中执行编码。所以:
$soapObject.byteArray = content
根本不需要base64String
。