Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display all content with Invoke-WebRequest

So I decided to start using PowerShell rather than Command Prompt. And I want to run curl. Very different output then discover that curl is an alias to Invoke-WebRequest in PowerShell.

Using PowerShell curl in the same way as real curl, I only get part of the content displayed.

I have seen that I can put the output of PowerShell curl into a variable and then use $variable.Content to display all of the content but that seems extra work over real curl.

Is there an option to show all of the content directly? I can't see one in the help.

like image 829
John Avatar asked Nov 20 '16 09:11

John


People also ask

What is invoke-WebRequest in PowerShell?

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

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

Invoke-RestMethod is perfect for quick APIs that have no special response information such as Headers or Status Codes, whereas Invoke-WebRequest gives you full access to the Response object and all the details it provides.

Does invoke-WebRequest use proxy?

Beginning in PowerShell 7.0, Invoke-WebRequest supports proxy configuration defined by environment variables.

Is invoke-WebRequest the same as curl?

In PowerShell, the cURL command is an alias of the Invoke-WebRequest cmdlet. The Invoke-WebRequest cmdlet is used to send requests to a website.


2 Answers

Unlike the curl command line utility Invoke-WebRequest returns an object with various properties of which the content of the requested document is just one. You can get the content in a single statement by expanding the property like this:

Invoke-WebRequest 'http://www.example.org/' | Select-Object -Expand Content 

or by getting the property value via dot-notation like this:

(Invoke-WebRequest 'http://www.example.org/').Content 

Alternatively you could use the Windows port of curl:

& curl.exe 'http://www.example.org/' 

Call the program with its extension to distinguish it from the alias curl for Invoke-WebRequest.

like image 67
Ansgar Wiechers Avatar answered Oct 05 '22 20:10

Ansgar Wiechers


Well, if you are bothered with extra typing this is the shortest way to achieve that (well, at least I can think of):

(iwr google.tt).content 
like image 41
4c74356b41 Avatar answered Oct 05 '22 20:10

4c74356b41