Exploring web requests

Web requests help us request data from Uniform Resource Identifier (URI). A developer performs many tasks using a web request, such as finding a response, downloading files, and reading files from the Internet.

In this topic, we will take a look at the cmdlets used for web requests and the WebRequest class.

Using the Windows PowerShell cmdlet, Invoke-WebRequest, we can perform a few tasks. Run the following command:

#Read the help document
help Invoke-WebRequest –Detailed

This gives the help content.

#Using the command
$site = Invoke-WebRequest http://www.Bing.com
$site | GM

This lists the members (Methods and Properties)

#Checking the Status Code
"The Site Status Code is `t" + $site.StatusCode
"Description`t" + $site.StatusDescription ...

Get PowerShell: Automating Administrative Tasks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.