Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1522,7 +1522,7 @@ internal void SetRequestContent(HttpRequestMessage request, XmlNode xmlNode)

byte[] bytes = null;
XmlDocument doc = xmlNode as XmlDocument;
if (doc?.FirstChild is XmlDeclaration decl)
if (doc?.FirstChild is XmlDeclaration decl && !string.IsNullOrEmpty(decl.Encoding))
{
Encoding encoding = Encoding.GetEncoding(decl.Encoding);
bytes = StreamHelper.EncodeToBytes(doc.OuterXml, encoding);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,15 @@ Describe "Invoke-WebRequest tests" -Tags "Feature", "RequireAdminOnWindows" {
$object.Data | Should -BeExactly 'проверка'
}

It "Invoke-WebRequest supports sending XML requests without encoding" {
$uri = Get-WebListenerUrl -Test POST
$body = '<?xml version="1.0"?><foo />'
$result = Invoke-WebRequest -Uri $uri -body ([xml]$body) -ContentType 'text/xml' -method 'POST'

$object = $result.Content | ConvertFrom-Json
$object.Data | Should -BeExactly $body
}

It "Invoke-WebRequest supports request that returns page containing CodPage 936 data." {
$uri = Get-WebListenerUrl -Test 'Encoding' -TestValue 'CP936'
$command = "Invoke-WebRequest -Uri '$uri'"
Expand Down Expand Up @@ -2347,6 +2356,14 @@ Describe "Invoke-RestMethod tests" -Tags "Feature", "RequireAdminOnWindows" {
$Result.Output.Data | Should -BeExactly 'проверка'
}

It "Invoke-RestMethod supports sending XML requests without encoding" {
$uri = Get-WebListenerUrl -Test POST
$body = '<?xml version="1.0"?><foo />'
$result = Invoke-RestMethod -Uri $uri -body ([xml]$body) -ContentType 'text/xml' -method 'POST'

$result.Data | Should -BeExactly $body
}

It "Invoke-RestMethod supports request that returns page containing Code Page 936 data." {
$uri = Get-WebListenerUrl -Test 'Encoding' -TestValue 'CP936'
$command = "Invoke-RestMethod -Uri '$uri'"
Expand Down