mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
[release/v7.4.2] Revert "Adjust PUT method behavior to POST one for default content type in WebCmdlets" (#21049) (#21428)
Co-authored-by: Steve Lee <slee@microsoft.com>
This commit is contained in:
co-authored by
Steve Lee
parent
c16cfe8f87
commit
b0692c1f07
+1
-1
@@ -1172,7 +1172,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
WebSession.ContentHeaders[HttpKnownHeaderNames.ContentType] = ContentType;
|
||||
}
|
||||
else if (request.Method == HttpMethod.Post || request.Method == HttpMethod.Put)
|
||||
else if (request.Method == HttpMethod.Post)
|
||||
{
|
||||
// Win8:545310 Invoke-WebRequest does not properly set MIME type for POST
|
||||
WebSession.ContentHeaders.TryGetValue(HttpKnownHeaderNames.ContentType, out string contentType);
|
||||
|
||||
@@ -795,14 +795,9 @@ Describe "Invoke-WebRequest tests" -Tags "Feature", "RequireAdminOnWindows" {
|
||||
($result.Output.Content | ConvertFrom-Json).method | Should -Be "TEST"
|
||||
}
|
||||
|
||||
It "Validate Invoke-WebRequest default ContentType for CustomMethod <method>" -TestCases @(
|
||||
@{method = "POST"}
|
||||
@{method = "PUT"}
|
||||
) {
|
||||
param($method)
|
||||
|
||||
$uri = Get-WebListenerUrl -Test $method
|
||||
$command = "Invoke-WebRequest -Uri '$uri' -CustomMethod $method -Body 'testparam=testvalue'"
|
||||
It "Validate Invoke-WebRequest default ContentType for CustomMethod POST" {
|
||||
$uri = Get-WebListenerUrl -Test 'Post'
|
||||
$command = "Invoke-WebRequest -Uri '$uri' -CustomMethod POST -Body 'testparam=testvalue'"
|
||||
$result = ExecuteWebCommand -command $command
|
||||
$jsonResult = $result.Output.Content | ConvertFrom-Json
|
||||
$jsonResult.form.testparam | Should -Be "testvalue"
|
||||
@@ -2858,13 +2853,9 @@ Describe "Invoke-RestMethod tests" -Tags "Feature", "RequireAdminOnWindows" {
|
||||
$result.Output.method | Should -Be "TEST"
|
||||
}
|
||||
|
||||
It "Validate Invoke-RestMethod default ContentType for CustomMethod <method>" -TestCases @(
|
||||
@{method = "POST"}
|
||||
@{method = "PUT"}
|
||||
) {
|
||||
param($method)
|
||||
$uri = Get-WebListenerUrl -Test $method
|
||||
$command = "Invoke-RestMethod -Uri '$uri' -CustomMethod $method -Body 'testparam=testvalue'"
|
||||
It "Validate Invoke-RestMethod default ContentType for CustomMethod POST" {
|
||||
$uri = Get-WebListenerUrl -Test 'Post'
|
||||
$command = "Invoke-RestMethod -Uri '$uri' -CustomMethod POST -Body 'testparam=testvalue'"
|
||||
$result = ExecuteWebCommand -command $command
|
||||
$result.Output.form.testparam | Should -Be "testvalue"
|
||||
$result.Output.Headers.'Content-Type' | Should -Be "application/x-www-form-urlencoded"
|
||||
|
||||
Reference in New Issue
Block a user