Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use PowerShell's Invoke-WebRequest in C#

Tags:

c#

powershell

PowerShell 3.0 offers a very decent new cmdlet called Invoke-WebRequest. Is there a way to make use of its functionality using C# respectively .NET without invoking the cmdlet directly? Is it even based on .NET?

Regards, Kevin

like image 318
bitfrickler Avatar asked Sep 20 '12 21:09

bitfrickler


People also ask

How does WebRequest invoke work?

The Invoke-WebRequest cmdlet sends HTTP and HTTPS requests to a web page or web service. It parses the response and returns collections of links, images, and other significant HTML elements. This cmdlet was introduced in PowerShell 3.0.

What is the difference between invoke RestMethod and invoke-WebRequest?

Invoke-RestMethod - unlike Invoke-WebRequest - has deserialization built in: with a JSON response, it automatically parses the JSON text returned into a [pscustomobject] graph as if ConvertFrom-Json had been applied to it.

What is Uri in invoke-WebRequest?

Invoke-WebRequest sends a request to the URI (Uniform Resource Identifier) which is also called Endpoint and retrieves the data from the Web Page. It directly works with the URL or with the REST API because some websites allow modifying the content using only APIs.

Is invoke-WebRequest the same as curl?

curl in PowerShell uses Invoke-WebRequest . From PowerShell 3.0 and above, you can use Invoke-WebRequest , which is equivalent to curl .


1 Answers

You can use System.Net.HttpWebRequest to do the same thing. you've got a codeproject article about that.

like image 92
JPBlanc Avatar answered Sep 23 '22 06:09

JPBlanc