4

I am trying to create HTTP client with PowerShell.
In some places like this and this, it shows that I need to create an object like that:

$client = [System.Net.Http.HttpClient]::new()

But PowerShell doesn't find any class after System.net.Http..
In Microsoft it shows that there is a class named HttpClient so I'm not sure why I can't see it with PowerShell.

I am using PowerShell 5.1.18362.1801.

zett42
  • 25,437
  • 3
  • 35
  • 72
E235
  • 11,560
  • 24
  • 91
  • 141

1 Answers1

8

Make sure to load the System.Net.Http assembly.

Add-Type -AssemblyName System.Net.Http
$client = [System.Net.Http.HttpClient]::new()
pfx
  • 20,323
  • 43
  • 37
  • 57