Files
inquiry_robot/deploy/_remote_probe_preview_sample.ps1
T

45 lines
2.3 KiB
PowerShell

$ErrorActionPreference = "Continue"
$bodyPath = Join-Path $env:TEMP "login-body.json"
Set-Content -Path $bodyPath -Value '{"username":"admin","password":"123456","captcha":"","checkKey":""}' -Encoding ASCII
$login = Invoke-RestMethod -Uri "http://127.0.0.1:8180/jeecgboot/sys/login" -Method POST -InFile $bodyPath -ContentType "application/json;charset=UTF-8"
$token = $login.result.token
$h = @{ "X-Access-Token" = $token }
$list = Invoke-RestMethod -Uri "http://127.0.0.1:8180/jeecgboot/inquiry/quoteTemplate/list?pageNo=1&pageSize=5" -Headers $h
$rec = @($list.result.records)[0]
Write-Host ("tpl=" + $rec.name + " versionId=" + $rec.versionId + " objectKey=" + $rec.objectKey)
$vid = $rec.versionId
# header auth
try {
$r = Invoke-WebRequest -Uri ("http://127.0.0.1:8180/jeecgboot/inquiry/quoteTemplate/previewSample?versionId=" + $vid) -Headers $h -UseBasicParsing -TimeoutSec 60
Write-Host ("header_auth status=" + $r.StatusCode + " len=" + $r.RawContentLength + " ctype=" + $r.Headers["Content-Type"] + " cd=" + $r.Headers["Content-Disposition"])
} catch {
$resp = $_.Exception.Response
if ($resp) {
$reader = New-Object IO.StreamReader($resp.GetResponseStream())
$txt = $reader.ReadToEnd()
Write-Host ("header_auth FAIL status=" + [int]$resp.StatusCode + " body=" + $txt.Substring(0, [Math]::Min(500, $txt.Length)))
} else { Write-Host ("header_auth ERR " + $_.Exception.Message) }
}
# query token (browser window.open style)
try {
$url = "http://127.0.0.1:8180/jeecgboot/inquiry/quoteTemplate/previewSample?versionId=$vid&token=$token"
$r2 = Invoke-WebRequest -Uri $url -UseBasicParsing -TimeoutSec 60
Write-Host ("query_token status=" + $r2.StatusCode + " len=" + $r2.RawContentLength)
} catch {
$resp = $_.Exception.Response
if ($resp) {
$reader = New-Object IO.StreamReader($resp.GetResponseStream())
$txt = $reader.ReadToEnd()
Write-Host ("query_token FAIL status=" + [int]$resp.StatusCode + " body=" + $txt.Substring(0, [Math]::Min(500, $txt.Length)))
} else { Write-Host ("query_token ERR " + $_.Exception.Message) }
}
# check file exists
if ($rec.objectKey) {
$up = "E:\wwwroot\data\upFiles"
$cands = @(
(Join-Path $up ($rec.objectKey -replace "/","\")),
$rec.objectKey
)
foreach ($p in $cands) { Write-Host ("exists " + $p + " => " + (Test-Path $p)) }
}
Write-Host "PROBE_DONE"