Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

powershell - 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.

question from:https://stackoverflow.com/questions/40702328/display-all-content-with-invoke-webrequest

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...