Invoke-WebRequest change of TypeName of Headers.Values
See original GitHub issuePrerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
Steps to reproduce
The TypeName of Headers.Values is System.String
in PS 5 and changes to System.String[]
in PS 7. Is this the desired behaviour?
Expected behavior
(Invoke-WebRequest "http://postman-echo.com/get").Headers.Values | Get-Member
TypeName: System.String
Actual behavior
(Invoke-WebRequest "http://postman-echo.com/get").Headers.Values | Get-Member
TypeName: System.String[]
Error details
No response
Environment data
PS C:\Users\carlo> $PSVersionTable
Name Value
---- -----
PSVersion 7.3.1
PSEdition Core
GitCommitId 7.3.1
OS Microsoft Windows 10.0.19045
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Visuals
No response
Issue Analytics
- State:
- Created 9 months ago
- Reactions:1
- Comments:6 (4 by maintainers)
Top Results From Across the Web
How to use Invoke-WebRequest to see the sent headers?
1 Answer. Invoke-WebRequest doesn't store the request header AFAIK. If you want specific values in the header then it expects you to specify ......
Read more >Invoke-WebRequest - PowerShell
By default, the Invoke-WebRequest cmdlet validates the values of well-known headers that have a standards-defined value format. The following example shows ...
Read more >PowerShell Invoke-WebRequest – Parse and scrape a ...
PowerShell's Invoke-WebRequest is a powerful cmdlet that allows you to download, parse, and scrape web pages.
Read more >Invoke-WebRequest - Curl command in windows not working
Cannot convert the value of type System String to IDictionary Join ... Invoke - WebRequest - Cannot bind parameter ' Headers ' -...
Read more >PowerShell Invoke-RestMethod
Invoke -RestMethod will inspect the Content-Type header and deserialize the JSON data into a PSCustomObject that you can use. $Objs = Invoke- ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yes, exactly.
We migrated from WebClient (Windows PowerShell) to new API - HttpClient (pwsh). As result underlying types were changed too. Now Headers is HttpResponseHeaders type and it is
IEnumerable<KeyValuePair<string, IEnumerable<string>>>
. And although we repackage this to Dictionary, value now remainsIEnumerable<string>
. As implementsation detail it is internallystring[]
but I think it is not reliable to use this fact, much less waste resources on repackaging.This definitely looks like an intentional change to support multiple values for a single header