Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Windows PowerShell for .NET Developers - Second Edition

You're reading from   Windows PowerShell for .NET Developers - Second Edition Efficiently administer and maintain your development environment with Windows PowerShell

Arrow left icon
Product type Paperback
Published in Oct 2015
Publisher
ISBN-13 9781785287435
Length 330 pages
Edition 2nd Edition
Arrow right icon
Toc

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

The preceding command outputs the status code and description, as shown in the following image:

Now, run the following command:

Invoke-WebRequest -Uri http://www.Bing.com

The Invoke-WebRequest cmdlet sends http(s), FTP, and file requests...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image