1

I have a powershell script that makes a SOAP call to an API:

[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

This works locally on my machine, but fails when I run it via TeamCity.
It does work when I remote into the agent and run script manually from the console.

The message I get from PowerShell is:

Exception calling "GetResponse" with "0" argument(s): "The remote server returned an error: (400) Bad Request."

Any suggestions on what could be going wrong or how to diagnose this further?
I was not able to capture any traffic using Fiddler, so any suggestions on that are also welcome.

Arnold Zokas
  • 8,306
  • 6
  • 50
  • 76
  • Do you get any error info? Have you seen this SO question? http://stackoverflow.com/questions/9165658/cant-get-basic-powershell-script-running-inside-team-city – Keith Hill Nov 23 '13 at 04:32
  • @KeithHill I do get an error response - I have now included it my question. – Arnold Zokas Nov 24 '13 at 11:24
  • `I was not able to capture any traffic using Fiddler` <-- why not? you need to capture a working request and a non-working request and compare them – wal Nov 24 '13 at 12:26
  • @wal is right. The error is coming from the server because it doesn't think your request is valid. The best way to debug that is to compare the non-working request with a working request in Fiddler. – Keith Hill Nov 24 '13 at 21:49
  • @wal I can capture requests I've sent, but not requests originating from TeamCity. – Arnold Zokas Nov 25 '13 at 10:21
  • @ArnoldZokas because the call originates from TeamCity? If yes, then put fiddler on the TeamCity box. – wal Nov 25 '13 at 10:33
  • @wal That's what I did. – Arnold Zokas Nov 25 '13 at 11:00
  • `I was not able to capture any traffic using Fiddler,` <-- why not? – wal Nov 25 '13 at 11:38
  • With fiddler running on the agent box, I could capture other http traffic, but not agent traffic. I suspect TeamCity agent is bypassing local proxies. I may be wrong. – Arnold Zokas Nov 25 '13 at 11:49

1 Answers1

0

The problem was, it turns out, the F5 API I was calling. There is a bug in the version of F5 we are using: under certain conditions requests get rejected with a 400-response.

Nothing to do with TeamCity/Powershell.

Arnold Zokas
  • 8,306
  • 6
  • 50
  • 76