WebRequest在TeamCity上失败,HTTP-400错误



我有一个powershell脚本,它对API进行SOAP调用:

[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
$request = [System.Net.WebRequest]::Create("https://***.***.***.***/iControl/iControlPortal.cgi")
$request.Method = "POST"
$request.Credentials = new-object System.Net.NetworkCredential @("username", "password")
$request.Proxy = new-object System.Net.WebProxy @("***.***.***.***", ****)
$request.PreAuthenticate = $true;
$request.CachePolicy = new-object System.Net.Cache.RequestCachePolicy "NoCacheNoStore"
$payload = '<?xml version="1.0"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"><soap:Body><q1:get_monitor_status xmlns:q1="urn:iControl:LocalLB/PoolMember"><pool_names href="#id1" /></q1:get_monitor_status><soapenc:Array id="id1"><Item>{0}</Item></soapenc:Array></soap:Body></soap:Envelope>' -f "my-pool"
$requestPayloadWriter = new-object System.IO.StreamWriter $request.GetRequestStream()
$requestPayloadWriter.Write($payload)
$requestPayloadWriter.Flush()
$requestPayloadWriter.Close()
$responsePayloadReader = new-object System.IO.StreamReader $request.GetResponse().GetResponseStream()
$pool_status = $responsePayloadReader.ReadToEnd()
$responsePayloadReader.Flush()
$responsePayloadReader.Close()
$pool_status

这在我的机器上本地工作,但当我通过TeamCity运行它时失败了
当我远程进入代理并从控制台手动运行脚本时,它确实有效。

我从PowerShell得到的消息是:

使用"0"参数调用"GetResponse"时发生异常:"远程服务器返回错误:(400)错误请求。"

关于可能出现的问题或如何进一步诊断,有什么建议吗
我无法使用Fiddler捕捉任何流量,因此也欢迎对此提出任何建议。

事实证明,问题是我调用的F5 API。在我们使用的F5版本中有一个错误:在某些情况下,请求会被400响应拒绝。

与TeamCity/Powershell无关。

最新更新