Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

invoke-webrequest: add page #8177

Merged
merged 14 commits into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions pages/windows/curl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# curl
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will overwrite the existing curl page in the common platform.


> In PowerShell, this command may be an alias of `Invoke-WebRequest` when the original `curl` program (<https://curl.se>) is not properly installed.

- Check whether `curl` is properly installed by printing its version number. If this command evaluates into an error, PowerShell may have substituted this command with `Invoke-WebRequest`:

`curl --version`

- View documentation for the original `curl` command:

`tldr curl -p common`

- View documentation for PowerShell's `Invoke-WebRequest` command:

`tldr invoke-webrequest`
25 changes: 25 additions & 0 deletions pages/windows/invoke-webrequest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 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}}`
7 changes: 7 additions & 0 deletions pages/windows/iwr.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# iwr

> This command is an alias of `Invoke-WebRequest` in PowerShell.

- View documentation for the original command:

`tldr invoke-webrequest`
15 changes: 15 additions & 0 deletions pages/windows/wget.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# wget
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. Let's remove these wget and curl pages from this pull request.

Copy link
Collaborator Author

@reinhart1010 reinhart1010 Jul 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote these two pages for two reasons. First is the fact that in PowerShell for Windows, both commands will be substituted with Invoke-WebRequest with incompatible set of accepted parameters when wget or curl is not visible on %PATH%:

image

and similarly, executing curl and wget without additional subcommand or parameters will still return the same prompt with Invoke-WebRequest if both aren't installed on %PATH%:

image

As far as I know there are some edge cases where a command documentation is split between common and OS-specific versions, e.g. common/cd and windows/cd. As long as tldr clients still can show the common or platform-specific versions of the same command I still prefer to keep windows/curl and windows/wget this way to avoid confusion among those PowerShell users.

Ah I forgot that the original documentation should be accessed with tldr {{curl|wget}} --platform common instead of tldr common/{{curl|wget}}.

Copy link
Member

@sbrl sbrl Jul 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see, thanks for clarifying this. This is a rather confusing situation, isn't it?

  • cmd.exe is the main shell for Windows, which if you have curl or wget installed works as on Linux
  • PowerShell is also an official shell distributed and enabled by default on Windows, where curl and wget resolve → Invoke-WebRequest
  • Someone should complain to Microsoft about this awfully confusing behaviour, since curl, wget, and Invoke-WebRequest all have incompatible arguments

With this in mind, your solution here seems to be the best option. Thanks for explaining - not being a Windows user I didn't understand at first.


> In PowerShell, this command may be an alias of `Invoke-WebRequest` when the original `wget` program (<https://www.gnu.org/software/wget>) is not properly installed.

- Check whether `wget` is properly installed by printing its version number. If this command evaluates into an error, PowerShell may have substituted this command with `Invoke-WebRequest`:

`curl --version`

- View documentation for the original `wget` command:

`tldr wget -p common`

- View documentation for PowerShell's `Invoke-WebRequest` command:

`tldr invoke-webrequest`