PowerShell:POST(小负载测试)后缺少 HTTP 响应代码

PowerShell: HTTP Response Code is missing following a POST (small load test)

大师们,我的代码已经完成了 99%,这是一个执行 HTTP POST 的 PowerShell 脚本。在其中,我试图打印以控制台来自位于第 7 层 API-GW 上的 Web 服务器的 HTTP 响应代码(第 7 层 API-GW 在强化 Linux 服务器)- 这不是 IIS。我理解通过在内存中绘制整个文件来执行 HTTP POST 的缺点,如下所示;我并不担心 - 我的负载测试很小,在 30 个 HTTP POSTs 后终止。我的问题是,为什么它不从服务器打印出 HTTP 响应代码?它正在获得答案,但在 PowerShell 控制台 window 中显示空白,而不是响应代码。

$FilePath = 'D:\Scripts\AVTest\Clean Files\AssetHandbook.pdf';
#Symantec:
$URL = 'https://labserver1.dev.local:8443/Scanfile/test';
#Sophos:
$fileBytes = [System.IO.File]::ReadAllBytes($FilePath);
# $fileEnc = [System.Text.Encoding]::GetEncoding('UTF-8').GetString($fileBytes);
$fileEnc = ([System.Text.Encoding]::GetEncoding("ISO-8859-1").GetString($fileBytes));
$boundary = [System.Guid]::NewGuid().ToString();
$LF = "`r`n";
$bodyLines = (
    "--$boundary",
    "Content-Disposition: form-data; name=`"file`"; filename=`"AssetHandbook.pdf`"",
    "Content-Type: application/octet-stream$LF",
    $fileEnc,
    "--$boundary--$LF"
) -join $LF
$SC = "";
 
$i=1
Do{
    Try{
        $SC=(Invoke-RestMethod -Uri $URL -Method Post -ContentType "multipart/form-data; boundary=`"$boundary`"" -Body $bodyLines).StatusCode
    }
    catch{
        $SC=($_.Exception.Response.StatusCode.value__)
    }
        
    Write-host($SC) -ForegroundColor Red -BackgroundColor Cyan
    $clipboard = $SC
    $i++
}
Until($SC -eq 429 -or $i -gt 30)
 
Set-Clipboard $clipboard
Start-Sleep -Second 1
Write-host $SC "<----- HTTP Status code" -ForegroundColor Red -BackgroundColor Cyan

下面的屏幕截图来自执行 HTTP GET 的不同脚本。这是我期待看到的:

使用我上面发布的当前脚本并执行 HTTP POST,这是我看到的:

根据docsInvoke-RestMethod可能的输出类型包括System.Int64System.StringSystem.Xml.XmlDocument。 None 其中包括一名 StatusCode 成员。

能用PS7的话,还有parameter-StatusCodeVariable。传递此参数时,cmdlet 会将给定变量设置为 return.

之后的 HTTP 状态代码