Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't find System.Net.Http.HttpClient class

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.

like image 201
E235 Avatar asked Oct 16 '25 11:10

E235


1 Answers

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

Add-Type -AssemblyName System.Net.Http
$client = [System.Net.Http.HttpClient]::new()
like image 50
pfx Avatar answered Oct 18 '25 04:10

pfx