I was playing around with Powershell and MCWS and came across the following problem;
Invoke-Restmethod and Invoke-WebRequest both fail with the following error when accessing the JRiver web service MCWS
Invoke-RestMethod http://localhost:52199/MCWS/v1/alive -Verbose
VERBOSE: GET http://localhost:52199/MCWS/v1/alive with 0-byte payload
VERBOSE: received 385-byte response of content type text/xml ; charset="utf-8"
Invoke-RestMethod : Value cannot be null.
Parameter name: name
At line:1 char:1
+ Invoke-RestMethod http://localhost:52199/MCWS/v1/alive -Verbose
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Invoke-RestMethod], ArgumentNullException
+ FullyQualifiedErrorId : System.ArgumentNullException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
The error returned is extremely opaque but fortunately I found an explanation here
http://stackoverflow.com/questions/36275618/why-is-invoke-webrequest-and-invoke-restmethod-failing-and-succeeding-at-the-samAs is explained on stackoverflow the error is caused because MCWS is returning a content header with the charset set as charset="utf-8" (quotes) as opposed to the more normal charset=utf-8 (no quotes)
Here is an example of Powershell working with a REST api that returns a content header with charset=utf-8 (no quotes)
Invoke-RestMethod $url -Verbose
VERBOSE: GET http://ibl.api.bbci.co.uk/ibl/v1/episodes/p03r3y5p?rights=web&availability=all with 0-byte payload
VERBOSE: received 2146-byte response of content type application/json; charset=utf-8
version schema episodes
------- ------ --------
1.0 /ibl/v1/schema/ibl.json {@{id=p03r3y5p; live=False; type=episode_large; (truncated response for clarity)
Now as noted on stackoverflow this is pretty sloppy from Microsoft but it leaves the problem that the JRiver MCWS api isn't accessible using standard methods from the standard Microsoft scripting language.
Is there a particular reason that the charset has been quoted and set this way in the MCWS content header?
Of course this issue can be worked around, I am using the following:
$mc_xml=New-Object XML
$mc_xml.Load("http://localhost:52199/MCWS/v1/alive")
But this is not the "normal" method to access a REST api in Powershell.
If anyone has has any other solutions for accessing MCWS using Powershell, I'd be grateful if they would share them.
Thanks,
Terry