diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 index 05356b2edf8..d9c62aa13b3 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 @@ -496,15 +496,15 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { It "Validate Invoke-WebRequest error with -Proxy and -NoProxy option" { $uri = Get-WebListenerUrl -Test 'Delay' -TestValue '10' - $command = "Invoke-WebRequest -Uri '$uri' -Proxy 'http://localhost:8080' -NoProxy -TimeoutSec 2" + $command = "Invoke-WebRequest -Uri '$uri' -Proxy 'http://127.0.0.1:8080' -NoProxy -TimeoutSec 2" $result = ExecuteWebCommand -command $command $result.Error.FullyQualifiedErrorId | Should Be "AmbiguousParameterSet,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" } $testCase = @( - @{ proxy_address = "http://localhost:9"; name = 'http_proxy'; protocol = 'http' } - @{ proxy_address = "http://localhost:9"; name = 'https_proxy'; protocol = 'https' } + @{ proxy_address = "http://127.0.0.1:9"; name = 'http_proxy'; protocol = 'http' } + @{ proxy_address = "http://127.0.0.1:9"; name = 'https_proxy'; protocol = 'https' } ) It "Validate Invoke-WebRequest error with -Proxy option set - ''" -TestCases $testCase { @@ -1632,15 +1632,15 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { It "Validate Invoke-RestMethod error with -Proxy and -NoProxy option" { $uri = Get-WebListenerUrl -Test 'Delay' -TestValue '10' - $command = "Invoke-RestMethod -Uri '$uri' -Proxy 'http://localhost:8080' -NoProxy -TimeoutSec 2" + $command = "Invoke-RestMethod -Uri '$uri' -Proxy 'http://127.0.0.1:8080' -NoProxy -TimeoutSec 2" $result = ExecuteWebCommand -command $command $result.Error.FullyQualifiedErrorId | Should Be "AmbiguousParameterSet,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" } $testCase = @( - @{ proxy_address = "http://localhost:9"; name = 'http_proxy'; protocol = 'http' } - @{ proxy_address = "http://localhost:9"; name = 'https_proxy'; protocol = 'https' } + @{ proxy_address = "http://127.0.0.1:9"; name = 'http_proxy'; protocol = 'http' } + @{ proxy_address = "http://127.0.0.1:9"; name = 'https_proxy'; protocol = 'https' } ) It "Validate Invoke-RestMethod error with -Proxy option - ''" -TestCases $testCase { diff --git a/test/tools/Modules/WebListener/WebListener.psm1 b/test/tools/Modules/WebListener/WebListener.psm1 index 7f9c69e307d..017c5a1c415 100644 --- a/test/tools/Modules/WebListener/WebListener.psm1 +++ b/test/tools/Modules/WebListener/WebListener.psm1 @@ -158,7 +158,8 @@ function Get-WebListenerUrl { return $null } $Uri = [System.UriBuilder]::new() - $Uri.Host = 'localhost' + # Use 127.0.0.1 and not localhost due to https://github.com/dotnet/corefx/issues/24104 + $Uri.Host = '127.0.0.1' $Uri.Port = $runningListener.HttpPort $Uri.Scheme = 'Http'