diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs index 1cef94d1685..841f6a60c72 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs @@ -815,12 +815,12 @@ private ErrorRecord GetValidationError(string msg, string errorId, params object private bool IsStandardMethodSet() { - return (ParameterSetName == "StandardMethod"); + return (ParameterSetName == "StandardMethod" || ParameterSetName == "StandardMethodNoProxy"); } private bool IsCustomMethodSet() { - return (ParameterSetName == "CustomMethod"); + return (ParameterSetName == "CustomMethod" || ParameterSetName == "CustomMethodNoProxy"); } private string GetBasicAuthorizationHeader() diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 index f63f3be140f..5f4f5c7728e 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 @@ -688,6 +688,13 @@ Describe "Invoke-WebRequest tests" -Tags "Feature", "RequireAdminOnWindows" { ($result.Output.Content | ConvertFrom-Json).args.testparam | Should -Be "testvalue" } + It "Validate Invoke-WebRequest body is converted to query params for CustomMethod GET and -NoProxy" { + $uri = Get-WebListenerUrl -Test 'Get' + $command = "Invoke-WebRequest -Uri '$uri' -CustomMethod GET -Body @{'testparam'='testvalue'} -NoProxy" + $result = ExecuteWebCommand -command $command + ($result.Output.Content | ConvertFrom-Json).query | Should -Be "?testparam=testvalue" + } + It "Validate Invoke-WebRequest returns HTTP errors in exception" { $query = @{ body = "I am a teapot!!!" @@ -2269,6 +2276,13 @@ Describe "Invoke-RestMethod tests" -Tags "Feature", "RequireAdminOnWindows" { $result.Output.args.testparam | Should -Be "testvalue" } + It "Validate Invoke-RestMethod body is converted to query params for CustomMethod GET and -NoProxy" { + $uri = Get-WebListenerUrl -Test 'Get' + $command = "Invoke-RestMethod -Uri '$uri' -CustomMethod GET -Body @{'testparam'='testvalue'} -NoProxy" + $result = ExecuteWebCommand -command $command + $result.Output.Query | Should -Be "?testparam=testvalue" + } + It "Validate Invoke-RestMethod returns HTTP errors in exception" { $query = @{ body = "I am a teapot!!!" diff --git a/test/tools/WebListener/Controllers/GetController.cs b/test/tools/WebListener/Controllers/GetController.cs index cadb34725a8..68ce98fb78f 100644 --- a/test/tools/WebListener/Controllers/GetController.cs +++ b/test/tools/WebListener/Controllers/GetController.cs @@ -36,6 +36,7 @@ public JsonResult Index() {"headers", headers}, {"origin" , Request.HttpContext.Connection.RemoteIpAddress.ToString()}, {"url" , UriHelper.GetDisplayUrl(Request)}, + {"query" , Request.QueryString.ToUriComponent()}, {"method" , Request.Method} };