Home > front end >  Can't find System.Net.Http.HttpClient class
Can't find System.Net.Http.HttpClient class

Time:12-31

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.

CodePudding user response:

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

Add-Type -AssemblyName System.Net.Http
$client = [System.Net.Http.HttpClient]::new()
  • Related