1
0
Fork 0
mirror of https://github.com/tldr-pages/tldr.git synced 2025-04-29 23:24:55 +02:00
tldr/pages/windows/invoke-webrequest.md
Reinhart Previano Koentjoro dc3ec35560
invoke-webrequest: add page (#8177)
* windows/get-*: Add PowerShell-only notice

* Update pages/windows/get-childitem.md

Co-authored-by: Axel Navarro <navarroaxel@gmail.com>

* windows/get-*: Change PowerShell notice

Co-authored-by: Axel Navarro <navarroaxel@gmail.com>

* invoke-item: Add command

* invoke-item: Remove quotations whenever possible

* invoke-item: Put all asterisk globs inside parameters

* invoke-item: More asterisk inside parameters

* Update pages/windows/invoke-item.md

Co-authored-by: Axel Navarro <navarroaxel@gmail.com>

* Update pages/windows/invoke-item.md

* invoke-webrequest: Add page with related aliases

* invoke-webrequest: Use LF instead of CRLF

* fix: Use -p parameter instead

Co-authored-by: Axel Navarro <navarroaxel@gmail.com>
2022-07-13 00:41:24 +01:00

1.1 KiB

Invoke-WebRequest

Performs a HTTP/HTTPS request to the Web. This command can only be used through PowerShell. More information: https://docs.microsoft.com/powershell/module/microsoft.powershell.utility/invoke-webrequest.

  • Download the contents of a URL to a file:

Invoke-WebRequest {{http://example.com}} -OutFile {{filename}}

  • Send form-encoded data (POST request of type application/x-www-form-urlencoded):

Invoke-WebRequest -Method Post -Body @{ name='bob' } {{http://example.com/form}}

  • Send a request with an extra header, using a custom HTTP method:

Invoke-WebRequest -Headers {{@{ X-My-Header = '123' }}} -Method {{PUT}} {{http://example.com}}

  • Send data in JSON format, specifying the appropriate content-type header:

Invoke-WebRequest -Body {{'{"name":"bob"}'}} -ContentType 'application/json' {{http://example.com/users/1234}}

  • Pass a username and password for server authentication:

Invoke-WebRequest -Headers @{ Authorization = "Basic "+ [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes("myusername:mypassword")) } {{http://example.com}}