【发布时间】: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