【问题标题】:Powershell Base64 String to BytesPowershell Base64 字符串到字节
【发布时间】:2016-03-23 15:06:03
【问题描述】:

我正在尝试将带有 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 表示法,我可以直接放置 Base64Encoded 字符串。但是powershell怎么办呢?

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

【问题讨论】:

  • 这里的soapObject 是什么?我希望如果它需要一个字节数组,那么您应该能够提供字节数组,并且代理会将其转换为 base64。
  • 就是这样!就像粘贴原始数据一样简单......为了完整起见,我添加了soapObject初始化。如果你把它放在一个答案中,我可以接受。

标签: string powershell soap base64 bytearray


【解决方案1】:

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

$soapObject.byteArray = content

根本不需要base64String

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-22
    • 2017-06-15
    • 1970-01-01
    • 2012-04-26
    • 2017-10-02
    • 1970-01-01
    相关资源
    最近更新 更多