8000 Add -PreserveAuthorizationHeader on redirect to Invoke-WebRequest and… · MicrosoftDocs/PowerShell-Docs@cc49efb · GitHub
[go: up one dir, main page]

Skip to content

Commit cc49efb

Browse files
dantraMSFTjuanpablojofre
authored andcommitted
Add -PreserveAuthorizationHeader on redirect to Invoke-WebRequest and Invoke-RestMethod to address fix for PowerShell/PowerShell#2227
1 parent 704abc0 commit cc49efb

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

reference/6/Microsoft.PowerShell.Utility/Invoke-RestMethod.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ Sends an HTTP or HTTPS request to a RESTful web service.
1616
## SYNTAX
1717

1818
```
19-
Invoke-RestMethod [-Uri] <uri> [-Method <WebRequestMethod>] [-FollowRelLink] [-MaximumFollowRelLink <int>] [-UseBasicParsing] [-WebSession <WebRequestSession>] [-SessionVariable <string>] [-Credential <pscredential>] [-UseDefaultCredentials] [-CertificateThumbprint <string>] [-Certificate <X509Certificate>] [-SkipCertificateCheck] [-UserAgent <string>] [-DisableKeepAlive] [-TimeoutSec <int>] [-Headers <IDictionary>] [-MaximumRedirection <int>] [-Proxy <uri>] [-ProxyCredential <pscredential>] [-ProxyUseDefaultCredentials] [-Body <Object>] [-ContentType <string>] [-TransferEncoding <string>] [-InFile <string>] [-OutFile <string>] [-PassThru] [<CommonParameters>]
19+
Invoke-RestMethod [-Uri] <uri> [-Method <WebRequestMethod>] [-FollowRelLink] [-MaximumFollowRelLink <int>] [-UseBasicParsing] [-WebSession <WebRequestSession>] [-SessionVariable <string>] [-Credential <pscredential>] [-UseDefaultCredentials] [-CertificateThumbprint <string>] [-Certificate <X509Certificate>] [-SkipCertificateCheck] [-UserAgent <string>] [-DisableKeepAlive] [-TimeoutSec <int>] [-Headers <IDictionary>] [-MaximumRedirection <int>] [-PreserveAuthorizationOnRedirect] [-Proxy <uri>] [-ProxyCredential <pscredential>] [-ProxyUseDefaultCredentials] [-Body <Object>] [-ContentType <string>] [-TransferEncoding <string>] [-InFile <string>] [-OutFile <string>] [-PassThru] [<CommonParameters>]
2020
21-
Invoke-RestMethod [-Uri] <uri> -NoProxy [-Method <WebRequestMethod>] [-FollowRelLink] [-MaximumFollowRelLink <int>] [-UseBasicParsing] [-WebSession <WebRequestSession>] [-SessionVariable <string>] [-Credential <pscredential>] [-UseDefaultCredentials] [-CertificateThumbprint <string>] [-Certificate <X509Certificate>] [-SkipCertificateCheck] [-UserAgent <string>] [-DisableKeepAlive] [-TimeoutSec <int>] [-Headers <IDictionary>] [-MaximumRedirection <int>] [-Body <Object>] [-ContentType <string>] [-TransferEncoding <string>] [-InFile <string>] [-OutFile <string>] [-PassThru] [<CommonParameters>]
21+
Invoke-RestMethod [-Uri] <uri> -NoProxy [-Method <WebRequestMethod>] [-FollowRelLink] [-MaximumFollowRelLink <int>] [-UseBasicParsing] [-WebSession <WebRequestSession>] [-SessionVariable <string>] [-Credential <pscredential>] [-UseDefaultCredentials] [-CertificateThumbprint <string>] [-Certificate <X509Certificate>] [-SkipCertificateCheck] [-UserAgent <string>] [-DisableKeepAlive] [-TimeoutSec <int>] [-Headers <IDictionary>] [-MaximumRedirection <int>] [-PreserveAuthorizationOnRedirect] [-Body <Object>] [-ContentType <string>] [-TransferEncoding <string>] [-InFile <string>] [-OutFile <string>] [-PassThru] [<CommonParameters>]
2222
23-
Invoke-RestMethod [-Uri] <uri> -CustomMethod <string> [-FollowRelLink] [-MaximumFollowRelLink <int>] [-UseBasicParsing] [-WebSession <WebRequestSession>] [-SessionVariable <string>] [-Credential <pscredential>] [-UseDefaultCredentials] [-CertificateThumbprint <string>] [-Certificate <X509Certificate>] [-SkipCertificateCheck] [-UserAgent <string>] [-DisableKeepAlive] [-TimeoutSec <int>] [-Headers <IDictionary>] [-MaximumRedirection <int>] [-Proxy <uri>] [-ProxyCredential <pscredential>] [-ProxyUseDefaultCredentials] [-Body <Object>] [-ContentType <string>] [-TransferEncoding <string>] [-InFile <string>] [-OutFile <string>] [-PassThru] [<CommonParameters>]
23+
Invoke-RestMethod [-Uri] <uri> -CustomMethod <string> [-FollowRelLink] [-MaximumFollowRelLink <int>] [-UseBasicParsing] [-WebSession <WebRequestSession>] [-SessionVariable <string>] [-Credential <pscredential>] [-UseDefaultCredentials] [-CertificateThumbprint <string>] [-Certificate <X509Certificate>] [-SkipCertificateCheck] [-UserAgent <string>] [-DisableKeepAlive] [-TimeoutSec <int>] [-Headers <IDictionary>] [-MaximumRedirection <int>] [-PreserveAuthorizationOnRedirect] [-Proxy <uri>] [-ProxyCredential <pscredential>] [-ProxyUseDefaultCredentials] [-Body <Object>] [-ContentType <string>] [-TransferEncoding <string>] [-InFile <string>] [-OutFile <string>] [-PassThru] [<CommonParameters>]
2424
25-
Invoke-RestMethod [-Uri] <uri> -CustomMethod <string> -NoProxy [-FollowRelLink] [-MaximumFollowRelLink <int>] [-UseBasicParsing] [-WebSession <WebRequestSession>] [-SessionVariable <string>] [-Credential <pscredential>] [-UseDefaultCredentials] [-CertificateThumbprint <string>] [-Certificate <X509Certificate>] [-SkipCertificateCheck] [-UserAgent <string>] [-DisableKeepAlive] [-TimeoutSec <int>] [-Headers <IDictionary>] [-MaximumRedirection <int>] [-Body <Object>] [-ContentType <string>] [-TransferEncoding <string>] [-InFile <string>] [-OutFile <string>] [-PassThru] [<CommonParameters>]
25+
Invoke-RestMethod [-Uri] <uri> -CustomMethod <string> -NoProxy [-FollowRelLink] [-MaximumFollowRelLink <int>] [-UseBasicParsing] [-WebSession <WebRequestSession>] [-SessionVariable <string>] [-Credential <pscredential>] [-UseDefaultCredentials] [-CertificateThumbprint <string>] [-Certificate <X509Certificate>] [-SkipCertificateCheck] [-UserAgent <string>] [-DisableKeepAlive] [-TimeoutSec <int>] [-Headers <IDictionary>] [-MaximumRedirection <int>] [-PreserveAuthorizationOnRedirect] [-Body <Object>] [-ContentType <string>] [-TransferEncoding <string>] [-InFile <string>] [-OutFile <string>] [-PassThru] [<CommonParameters>]
2626
```
2727

2828
## DESCRIPTION
@@ -418,6 +418,23 @@ Accept pipeline input: False
418418
Accept wildcard characters: False
419419
```
420420

421+
### -PreserveAuthorizationOnRedirect
422+
Indicates the cmdlet should preserve the Authorization header, when present, across redirections.
423+
424+
By default, the cmdlet strips the Authorization header before redirecting. Specifying this parameter disables this logic for cases where the header needs to be sent to the redirection location.
425+
426+
```yaml
427+
Type: SwitchParameter
428+
Parameter Sets: (All)
429+
Aliases:
430+
431+
Required: False
432+
Position: Named
433+
Default value: None
434+
Accept pipeline input: False
435+
Accept wildcard characters: False
436+
```
437+
421438
### -Method
422439
Specifies the method used for the web request.
423440
The acceptable values for this parameter are:

reference/6/Microsoft.PowerShell.Utility/Invoke-WebRequest.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Gets content from a web page on the Internet.
1919
Invoke-WebRequest [-UseBasicParsing] [-Uri] <Uri> [-WebSession <WebRequestSession>]
2020
[-SessionVariable <String>] [-Credential <PSCredential>] [-UseDefaultCredentials]
2121
[-CertificateThumbprint <String>] [-Certificate <X509Certificate>] [-UserAgent <String>]
22-
[-DisableKeepAlive] [-TimeoutSec <Int32>] [-Headers <IDictionary>] [-MaximumRedirection <Int32>]
22+
[-DisableKeepAlive] [-TimeoutSec <Int32>] [-Headers <IDictionary>] [-MaximumRedirection <Int32>] [-PreserveAuthorizationOnRedirect]
2323
[-Method <WebRequestMethod>] [-Proxy <Uri>] [-ProxyCredential <PSCredential>]
2424
[-ProxyUseDefaultCredentials] [-NoProxy] [-Body <Object>] [-ContentType <String>]
2525
[-TransferEncoding <String>] [-InFile <String>] [-OutFile <String>] [-PassThru]
@@ -359,6 +359,23 @@ Accept pipeline input: False
359359
Accept wildcard characters: False
360360
```
361361
362+
### -PreserveAuthorizationOnRedirect
363+
Indicates the cmdlet should preserve the Authorization header, when present, across redirections.
364+
365+
By default, the cmdlet strips the Authorization header before redirecting. Specifying this parameter disables this logic for cases where the header needs to be sent to the redirection location.
366+
367+
```yaml
368+
Type: SwitchParameter
369+
Parameter Sets: (All)
370+
Aliases:
371+
372+
Required: False
373+
Position: Named
374+
Default value: None
375+
Accept pipeline input: False
376+
Accept wildcard characters: False
377+
```
378+
362379
### -Method
363380
Specifies the method used for the web request.
364381
The acceptable values for this parameter are:

0 commit comments

Comments
 (0)
0