【问题标题】:Powershell Websocket Client Send ImagePowershell Websocket 客户端发送图像
【发布时间】:2020-10-01 19:15:06
【问题描述】:

参考文斯派克在此处提供的解决方案: How to use a Websocket client to open a long-lived connection to a URL, using PowerShell V2?

发送文本运行良好。如何发送PNG格式或二进制数据等图片?

发送文本的示例来源:

$Size = 1024
$Array = [byte[]] @(,0) * $Size
$Message = "Sample Message"
$Command = [System.Text.Encoding]::UTF8.GetBytes($Message)
$Send = New-Object System.ArraySegment[byte] -ArgumentList @(,$Command)            
$Conn = $WS.SendAsync($Send, [System.Net.WebSockets.WebSocketMessageType]::Text, $true, $CT)
While (!$Conn.IsCompleted) {
    Start-Sleep -Milliseconds 100
}

【问题讨论】:

  • 你可以试试[Byte[]]$Command = [System.IO.File]::ReadAllBytes(<Absolute\Path\To\The\Image\Or\Binary\File>) 并像$Conn = $WS.SendAsync($Send, [System.Net.WebSockets.WebSocketMessageType]::Binary, $true, $CT) 一样发送吗?
  • 这样就解决了。谢谢!

标签: image powershell websocket client send


【解决方案1】:

@Theo 的评论解决了它:

[Byte[]]$Command = [System.IO.File]::ReadAllBytes(<Absolute\Path\To\The\Image\Or\Binary\File>) 
$Conn = $WS.SendAsync($Send, [System.Net.WebSockets.WebSocketMessageType]::Binary, $true, $CT)

【讨论】:

    猜你喜欢
    • 2019-10-15
    • 2014-02-26
    • 2017-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-18
    • 2016-05-13
    相关资源
    最近更新 更多