You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In-PRIndicates that a PR is out for the issueIssue-Enhancementthe issue is more of a feature request than a bugResolution-FixedThe issue is fixed.Up-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Cmdletsgeneral cmdlet issues
The version probably needs to be set in two places since the SendAsync method doesn't use the DefaultRequestVersion. For example the Invoke-WebRequest script:
The use of SocketsHttpHandler offers a number of advantages:
* A significant performance improvement when compared with the previous implementation.
* The elimination of platform dependencies, which simplifies deployment and servicing. For example, libcurl is no longer a dependency on .NET Core for macOS and .NET Core for Linux.
* Consistent behavior across all .NET platforms.
HttpClient has DefaultRequestVersion property of Version type. I think we should use Version for the new parameter since new HTTP versions may appear in the future. Argument completer would be great addition. Current supported list is in HttpVersion class
Unfortunately, the specific reasons of the change from HTTP2 back to HTTP1.1 wasn't made clear in the dotnet/runtime thread.
From my understanding, they say that 2.0 and 3.0 are de-facto specific enhancements of 1.1 but not new protocols. So users should explicitly point that they want to use.
The Invoke-RestMethod cmdlet sends HTTP and HTTPS requests to Representational State Transfer (REST) web services that return richly structured data. PowerShell formats the response based to the data type. For an RSS or ATOM feed, PowerShell returns the Item or Entry XML nodes. For JavaScript Object Notation (JSON) or XML, PowerShell converts, or deserializes, the content into [pscustomobject] objects. Comments are permitted in the JSON data. Note When the REST endpoint returns multiple objects, the objects are received as an array. If you pipe the output from Invoke-RestMethod to another command, it's sent as a single [Object[]] object. The contents of that array aren't enumerated for the next command on the pipeline. This cmdlet is introduced in Windows PowerShell 3.0. Beginning in PowerShell 7.0, Invoke-RestMethod supports proxy configuration defined by environment variables. See the NOTES section of this article. Beginning in PowerShell 7.4, character encoding for requests defaults to UTF-8 instead of ASCII. If you need a different encoding, you must set the charset attribute in the Content-Type header.
sergeevabc
So, with PowerShell 5.1 and 7.2.* it is not possible to connect using HTTP/2?
dmex (@dmex)
You need to add the -HttpVersion parameter for HTTP2/3.
$ pwsh --versionPowerShell 7.2.24
$ pwsh -c "irm -Uri https://cloudflare.com/cdn-cgi/trace -HttpVersion 2"Invoke-RestMethod: A parameter cannot be found that matches parameter name 'HttpVersion'.
$ pwsh -c "iwr -Uri https://cloudflare.com/cdn-cgi/trace -HttpVersion 2"Invoke-WebRequest: A parameter cannot be found that matches parameter name 'HttpVersion'.
I've indicated twice which versions of Powershell I'm interested in
Your post contains 3 lines of command output and doesn't include any text or mention anything about version requirements? If you can't update to the latest version, then it would help to mention you have a specific requirement for some old version of powershell because otherwise everyone is going to provide information from the most recent update.
you persistently continue to show me what version 7.5.0, which I'm not interested in, is capable of.
Yes, because the latest version is the correct answer.
If you need HTTP/2 support with v7.2.24 then your only option is using .NET methods from a custom function. Here's a basic example that is compatible with v7.2.24:
In-PRIndicates that a PR is out for the issueIssue-Enhancementthe issue is more of a feature request than a bugResolution-FixedThe issue is fixed.Up-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Cmdletsgeneral cmdlet issues
Activity
vexx32 commentedon May 13, 2020
Please provide the information requested in the issue template. There's really not a lot to go on here.
For reference, the API used by the cmdlets is here: https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient?view=netcore-3.1
There is reference to support for other versions of HTTP via this API / the SendAsync() method: https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient.defaultrequestversion?view=netcore-3.1
I'm not sure on the state of HTTP2 support on the web cmdlets by default.
iSazonov commentedon May 13, 2020
It seems we could consider new
HttpVersionparameter for all web cmdlets.dmex commentedon May 30, 2020
The version probably needs to be set in two places since the SendAsync method doesn't use the DefaultRequestVersion. For example the Invoke-WebRequest script:
PowerShell/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs
Line 1038 in 0f16d0e
httpClient.DefaultRequestVersion = new Version(2, 0);PowerShell/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs
Lines 1079 to 1080 in 0f16d0e
request.Version = new Version(2, 0);hayhay27 commentedon Jul 28, 2021
could we same time replace HttpClientHandler by SocketsHttpHandler?
iSazonov commentedon Jul 28, 2021
SocketsHttpHandler is an implementation of HttpClientHandler.
hayhay27 commentedon Jul 31, 2021
My fault. I miss sentence about HttpClientHandler implementation.
Anyway. I want to add new parameter HttpVersion for
irmandiwr:And fill
request.Versionaccording toHttpVersionIf it's ok I'll create PR
iSazonov commentedon Jul 31, 2021
HttpClienthasDefaultRequestVersionproperty ofVersiontype. I think we should useVersionfor the new parameter since new HTTP versions may appear in the future. Argument completer would be great addition. Current supported list is in HttpVersion classCome on!
SteveL-MSFT commentedon Sep 7, 2021
If we follow
curl's lead, we should default to 2.0 and fallback to 1.1 if negotiation fails: https://everything.curl.dev/http/versions#:~:text=Since%20perhaps%20mid%202016%2C%20curl%20will%20default%20to,capable%20curls%20get%201.1%20over%20HTTPS%20by%20default.But also expose a
HttpVersionif the user wants to be explicit.hayhay27 commentedon Sep 7, 2021
should we consider this as breaking change? default version was changed in dotnet 2.1 and reverted in 3.0 for reasons unknown to me
If we definitely follow curl's I can set default as 2.0
done
2 remaining items
iSazonov commentedon Sep 9, 2021
From my understanding, they say that 2.0 and 3.0 are de-facto specific enhancements of 1.1 but not new protocols. So users should explicitly point that they want to use.
flawrist commentedon Apr 17, 2025
So, with PowerShell 5.1 and 7.2.* it is not possible to connect using HTTP/2?
dmex commentedon Apr 19, 2025
sergeevabc This issue was fixed 5 years ago? You need to add the
-HttpVersionparameter for HTTP2/3.The powershell documentation has examples for HTTP/2 and it's the same for HTTP/3:
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-restmethod?view=powershell-7.5#example-8-send-a-request-using-http-2-0
flawrist commentedon Apr 20, 2025
dmex commentedon Apr 21, 2025
sergeevabc
flawrist commentedon Apr 21, 2025
iSazonov commentedon Apr 21, 2025
sergeevabc Please follow CoC.
The commit you ask was merged in 7.3 milestone
PowerShell/CHANGELOG/7.3.md
Line 1120 in 92c6f7a
dmex commentedon Apr 21, 2025
Your post contains 3 lines of command output and doesn't include any text or mention anything about version requirements? If you can't update to the latest version, then it would help to mention you have a specific requirement for some old version of powershell because otherwise everyone is going to provide information from the most recent update.
Yes, because the latest version is the correct answer.
If you need HTTP/2 support with v7.2.24 then your only option is using .NET methods from a custom function. Here's a basic example that is compatible with v7.2.24:
Then call Invoke-HttpClient and print some output:
flawrist commentedon Apr 21, 2025
I mentioned PS 5.1 and 7.2.* in my original question, then repeated this requirement.
Does not work, alas, still HTTP/1.1.
flawrist commentedon Jun 15, 2025
I got Pwsh 7.5.1, but
-HttpVersion 2did not work on my end (with Windows 7).However, Microsoft Edge v109 outputs
http/3, tls=TLSv1.3, even older versions do too.Explanation:
Conclusion: