Invoke-WebRequest and HTTP header If-Modified-Since to be set by user - by Vidar F

Status : 


Sign in
to vote
ID 766761 Comments
Status Active Workarounds
Type Suggestion Repros 0
Opened 10/9/2012 11:13:35 AM
Access Restriction Public


I want to use Powershell to check for updates on a server page feed, but I want to do it as efficient as possible. The site I want to interact with encourages developers to respect "Last-Modifed"-header from server and also to send "If-Modified-Since" header in the request. This will minimize the strain on the server and prevent unnecessary page loads.

Trying to set this header manually will cause an error:

Invoke-WebRequest : This header must be modified using the appropriate property or method.
Parameter name: name
At line:2 char:6
+ $r = Invoke-WebRequest -Uri "" -Headers $headers
+      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Invoke-WebRequest], ArgumentException
    + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

Why is this not allowed to be set?

Header should be allowed to be set manually in the -Header list or be exposed as a property/parameter.

This blog post explains a bit more:
Sign in to post a comment.