Powershell Base64字符串到字节

时间:2016-03-23 15:06:03

标签: string powershell soap base64 bytearray

我正在尝试将带有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 String。但是如何处理PowerShell?

<customType><byteArray>anyBase64String</byteArray></customType>

1 个答案:

答案 0 :(得分:2)

如果soapObject.byteArray期望一个字节数组,我希望能够给它一个数组 - 让代理在base64中执行编码。所以:

$soapObject.byteArray = content

根本不需要base64String