2

PowerShell 7's Invoke-WebRequest is much slower than PowerShell 5.1's. In some cases four-to-five times slower, as outlined in this issue. But even measuring the most basic web requests between the two, PowerShell 7's is at least twice as slow. This is because it's based on System.Net.Http.HttpClient instead of System.Net.WebRequest.

What I'd like to know is if there is a PowerShell 7 function out there that supports all the same parameters, but calls the WebRequest .NET methods instead of HttpClient. That way, until this issue is properly addressed, I'm covered without having to change my scripts around, or at least not radically so.

Vopel
  • 662
  • 6
  • 11
  • 1
    That same issue shows several work arounds. One even mentioning switching back to curl.exe. Would that be an option for you? You could possibly create your own as well, given that you use `System.Net.WebRequest` class. – Abraham Zinala Jan 04 '22 at 03:51
  • @AbrahamZinala Regarding why I don't want to use curl: The thing I want to emphasize is a drop-in replacement. Having to majorly rework a lot of my scripts isn't ideal for a problem that might be fixed within the year. Plus, they're pretty reliant on PowerShell's object property functionality, especially when it comes to headers. – Vopel Jan 04 '22 at 17:46
  • @AbrahamZinala Regarding making my own: That is a possibility. Thing is, I wanted to see if what I'm describing exists somewhere already, or maybe even see if someone better at PowerShell than I am wants to make it. Normally, when it comes to checking if something is out there already, search engine results suffice, but in this case, 'WebRequest' is both the .NET and the suffix of the function, so that makes the search results unreliable. – Vopel Jan 04 '22 at 17:50

0 Answers0