question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Invoke-WebRequest change of TypeName of Headers.Values

See original GitHub issue

Prerequisites

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:closed
  • Created 9 months ago
  • Reactions:1
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
iSazonovcommented, Jan 5, 2023

but whether a single header entry may be composed of multiple strings.

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 remains IEnumerable<string>. As implementsation detail it is internally string[] but I think it is not reliable to use this fact, much less waste resources on repackaging.

1reaction
SteveL-MSFTcommented, Jan 5, 2023

This definitely looks like an intentional change to support multiple values for a single header

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found