Title: WebClient needs to expose the timeout property (or improve Invoke-WebRequest implementation) when downloading large files · Issue #4679 · PowerShell/PowerShell · GitHub
Open Graph Title: WebClient needs to expose the timeout property (or improve Invoke-WebRequest implementation) when downloading large files · Issue #4679 · PowerShell/PowerShell
X Title: WebClient needs to expose the timeout property (or improve Invoke-WebRequest implementation) when downloading large files · Issue #4679 · PowerShell/PowerShell
Description: I have been having some issues interacting with REST full APIs, specifically with our product (Pexip) which is writing with Python and Django and uses Apache. Some of these issues are outlined in #2112 and #4274 and this involves a simil...
Open Graph Description: I have been having some issues interacting with REST full APIs, specifically with our product (Pexip) which is writing with Python and Django and uses Apache. Some of these issues are outlined in #...
X Description: I have been having some issues interacting with REST full APIs, specifically with our product (Pexip) which is writing with Python and Django and uses Apache. Some of these issues are outlined in #...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/4679
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"WebClient needs to expose the timeout property (or improve Invoke-WebRequest implementation) when downloading large files ","articleBody":"I have been having some issues interacting with REST full APIs, specifically with our product (Pexip) which is writing with Python and Django and uses Apache. Some of these issues are outlined in #2112 and #4274 and this involves a similar an linked problem. I also added a comment to https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-webrequest?view=powershell-5.1 that outlines this issue that I have repeated below:\r\n\r\n# Attempting to download a large file, GETting from a REST API.\r\n## The Basic Invoke-WebRequest\r\n\r\n```\r\n Invoke-WebRequest -Method Get -Uri $resource -cred $cred -OutFile $Destination -TimeoutSec 1800\r\n```\r\n\r\nThis would be the ideal. I can set timeout values and seemingly achieve what I want in one line. Unfortunately, this completely locked up the machine the script was running on. Basically, all the memory was consumed and after an hour or so, I had to end the script – of the 3.5 GB file, I think 200 MB was downloaded! What I needed is a way to stream the remote file to a local file without loading everything into memory.\r\n\r\n## Using WebClient\r\nThis seemed a lot better, however, the WebClient has no timeout property!!!\r\n\r\n```\r\n $wc = New-Object System.Net.WebClient \r\n $wc.Credentials = New-Object System.Net.NetworkCredential($User, $Pass)\r\n $wc.Headers.Add(\"Authorization\", \"Basic $encoded\")\r\n $wc.DownloadFile($resource, $DestinationPath)\r\n```\r\n\r\nThis is what I ended up using and in order to get the timeout to work, I used an extended class – luckily someone clever than I has achieved this for PowerShell using a C# class (https://koz.tv/setup-webclient-timeout-in-powershell/) although I assume the native classes in PS could also be used – but why?\r\n\r\nI have also found that I must add the additional Authorisation Headers, otherwise the client will get challenged then end up download the file effectively twice. Using Fiddler and watching the Ethernet stats, you can see this happen. Indeed, this seemingly occurred for all methods\r\n\r\n## Using HTTP client.\r\nWell I tried and failed dismally. However, I seem to create the Httpclient, it only ever seemed to stream the remote file into memory before dumping to a file. I know what I wanted to do, but do not have the wherewithal to do it.\r\n","author":{"url":"https://github.com/swinster","@type":"Person","name":"swinster"},"datePublished":"2017-08-26T15:49:34.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":10},"url":"https://github.com/4679/PowerShell/issues/4679"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:92f36de8-f158-97e9-6c3a-7fa49705de05 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A356:24BC9A:20954D7:2B5B6A5:6A546407 |
| html-safe-nonce | e88a56c5fe3d3717ce86a166cb136d15d16fe5851d7e0823e430f0abd5aed8db |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMzU2OjI0QkM5QToyMDk1NEQ3OjJCNUI2QTU6NkE1NDY0MDciLCJ2aXNpdG9yX2lkIjoiNTkyNzg2MzM2Nzc5MjYxNjQ1NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | add91d7607083e533ab098ccd4e9f4337a0e78318569496a8b94822c8f951038 |
| hovercard-subject-tag | issue:253102796 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/4679/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e193c61fa329909d840c9c1ba47e7d2e6015ba9475d25974e23e24abab2932b0/PowerShell/PowerShell/issues/4679 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e193c61fa329909d840c9c1ba47e7d2e6015ba9475d25974e23e24abab2932b0/PowerShell/PowerShell/issues/4679 |
| og:image:alt | I have been having some issues interacting with REST full APIs, specifically with our product (Pexip) which is writing with Python and Django and uses Apache. Some of these issues are outlined in #... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | swinster |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 49609581 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49609581 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 6d28624802c2f7d9500239dd6870ed7031b7353b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width