1

I'm trying to call a REST service that requires a Date header in the request. When I try something like

Invoke-RestMethod -Uri "http://path/to/my/service" -Header @{"Date"="Fri, 20 Mar 2015 16:00:00 GMT"}

I get an error

The 'Date' header must be modified using the appropriate property or method.

I found this question which addresses similar problems with a WebRequest in C#. I can't use HeaderProperty here (which appears to be the C# fix) -- is there anything else, or am I just unable to call this service from PowerShell?

Community
  • 1
  • 1
Coderer
  • 25,844
  • 28
  • 99
  • 154
  • It seems that this property can be modified in HttpWebRequest class only if you use .NET 4.0 or above - https://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.date.aspx. I think that Invoke-RestMethod use HttpWebRequest class for requests. I run your code using powershell 4.0 without any errors. There are some solutions on stackoverflow about how to run old version of powershell with .NET 4.0, for example. – Kostia Shiian Mar 20 '15 at 15:33
  • The output of `$PSVersionTable` includes `CLRVersion = 4.0.30319.18063`. The `PSVersion` is 3.0 -- maybe it also needs to be PS 4.0+? – Coderer Mar 20 '15 at 15:46
  • Try to update version to 4.0. It's possible for Windows 7 (Windows 2008). – Kostia Shiian Mar 20 '15 at 15:48
  • Corporate IT, out of my control. If it does turn out to be a version-of-powershell thing, then I guess I'm stuck with writing Actual Code :-/ – Coderer Mar 20 '15 at 15:50

0 Answers0