| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- param(
- [string]$Url = 'http://127.0.0.1:8099/',
- [int]$TimeoutMs = 0,
- [string]$Body = '{"params":[],"code":"99070061"}'
- )
- # Reproduces the request-issuing logic of HttpServices.cs Post() so that the
- # measured timeout is the same one UppPay would experience in production.
- $ErrorActionPreference = 'Stop'
- $u = [Uri]$Url
- $req = [System.Net.HttpWebRequest]::Create($u)
- $req.Method = 'POST'
- $req.ContentType = 'application/json'
- $req.AllowAutoRedirect = $true
- $req.MaximumAutomaticRedirections = 1
- $bytes = [System.Text.Encoding]::UTF8.GetBytes($Body)
- $req.ContentLength = $bytes.Length
- if ($TimeoutMs -gt 0) {
- $req.Timeout = $TimeoutMs
- $req.ReadWriteTimeout = $TimeoutMs
- Write-Host "mode : Timeout EXPLICITLY set"
- } else {
- Write-Host "mode : Timeout NOT set (exactly like UppPay today)"
- }
- Write-Host ("effective Timeout = {0} ms ({1:N1} s)" -f $req.Timeout, ($req.Timeout / 1000))
- Write-Host ("effective ReadWriteTimeout = {0} ms" -f $req.ReadWriteTimeout)
- Write-Host ("target : {0}" -f $Url)
- Write-Host ("body : {0}" -f $Body)
- Write-Host "-" * 70
- $sw = [System.Diagnostics.Stopwatch]::StartNew()
- try {
- $s = $req.GetRequestStream()
- $s.Write($bytes, 0, $bytes.Length)
- $s.Close()
- $resp = $req.GetResponse()
- $sr = New-Object System.IO.StreamReader($resp.GetResponseStream(), [System.Text.Encoding]::UTF8)
- $txt = $sr.ReadToEnd()
- $sr.Close(); $resp.Close()
- $sw.Stop()
- Write-Host ("RESULT: SUCCESS after {0:N2} s http={1}" -f $sw.Elapsed.TotalSeconds, [int]$resp.StatusCode)
- Write-Host ("BODY : {0}" -f $txt)
- } catch {
- $sw.Stop()
- Write-Host ("RESULT: FAILED after {0:N2} s" -f $sw.Elapsed.TotalSeconds)
- Write-Host "exception chain:"
- $ex = $_.Exception
- $level = 0
- while ($null -ne $ex -and $level -lt 6) {
- Write-Host (" [{0}] {1}" -f $level, $ex.GetType().FullName)
- Write-Host (" Message : {0}" -f $ex.Message)
- if ($ex -is [System.Net.WebException]) {
- Write-Host (" Status : {0}" -f $ex.Status)
- }
- $ex = $ex.InnerException
- $level++
- }
- }
- Write-Host ("elapsed = {0:N2} s" -f $sw.Elapsed.TotalSeconds)
|