Title: Invoke-WebRequest multipart form-data fails file upload when field names not quoted · Issue #6780 · PowerShell/PowerShell · GitHub
Open Graph Title: Invoke-WebRequest multipart form-data fails file upload when field names not quoted · Issue #6780 · PowerShell/PowerShell
X Title: Invoke-WebRequest multipart form-data fails file upload when field names not quoted · Issue #6780 · PowerShell/PowerShell
Description: This happens using the new -Form parameter that takes a hashtable of values and creates the multi-part form data. Steps to reproduce Find URL to webservice that accepts POST of multi-part form data Run Fiddler or Wireshark to observe the...
Open Graph Description: This happens using the new -Form parameter that takes a hashtable of values and creates the multi-part form data. Steps to reproduce Find URL to webservice that accepts POST of multi-part form data...
X Description: This happens using the new -Form parameter that takes a hashtable of values and creates the multi-part form data. Steps to reproduce Find URL to webservice that accepts POST of multi-part form data...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/6780
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Invoke-WebRequest multipart form-data fails file upload when field names not quoted","articleBody":"This happens using the new `-Form` parameter that takes a hashtable of values and creates the multi-part form data.\r\n\r\nSteps to reproduce\r\n------------------\r\n1. Find URL to webservice that accepts POST of multi-part form data\r\n2. Run Fiddler or Wireshark to observe the request body\r\n3. Execute IWR similar to below:\r\n\r\n```powershell\r\nInvoke-WebRequest -Uri $Uri -Method POST -Form @{\r\n APPLICATION_NAME = \"Name\"\r\n APPLICATION_VERION = \"3.0\"\r\n UPLOADED_FILE = Get-Item .\\foo.zip\r\n}\r\n```\r\n\r\nExpected behavior\r\n-----------------\r\nUpload works as it does when using Python script to upload the file. Observe that in this Fiddler trace, that the form-data field values are quoted:\r\n\r\n\r\n\r\nActual behavior\r\n---------------\r\nPowerShell fails and after some experimenting it is because the name values are not quoted:\r\n\r\n\r\n\r\nWith just a few extra quotes e.g.:\r\n\r\n```powershell\r\nInvoke-WebRequest -Uri $Uri -Method POST -Form @{\r\n '\"APPLICATION_NAME\"' = \"Name\"\r\n '\"APPLICATION_VERION\"' = \"3.0\"\r\n '\"UPLOADED_FILE\"' = Get-Item .\\foo.zip\r\n}\r\n```\r\n\r\nI can get the PowerShell request to quote all the field data values **except** the file's `filename` field. And that is enough to break the upload. Besides that, the above workaround is ugly.\r\n\r\nAs an aside, is there a way to control the filename value? If there was, I could work-around this by supplying the quotes myself. Also, I could see someone wanting to change the filename to something other than the original file's filename.\r\n\r\nThis also makes me wonder if we could use a new parameter like `-RequestFilter` that took a scriptblock with a signature like `{param($requestText) ... }` where you could get the request text just before it is sent. Then you could manipulate it however you needed to and return that text from this scriptblock. With such a feature I might be able to do this:\r\n\r\n```powershell\r\nInvoke-WebRequest -Uri $Uri -Method POST `\r\n -RequesetFilter {param($r) $r -replace '(?\u003c=filename=)(\\S+)','\"$1\"' } `\r\n -Form @{\r\n '\"APPLICATION_NAME\"' = \"Name\"\r\n '\"APPLICATION_VERION\"' = \"3.0\"\r\n '\"UPLOADED_FILE\"' = Get-Item .\\foo.zip\r\n }\r\n```\r\n\r\nEnvironment data\r\n----------------\r\n\r\n\u003c!-- provide the output of $PSVersionTable -->\r\n\r\n```powershell\r\n> $PSVersionTable\r\nName Value\r\n---- -----\r\nPSVersion 6.1.0-preview.2\r\nPSEdition Core\r\nGitCommitId v6.1.0-preview.2\r\nOS Microsoft Windows 10.0.16299\r\nPlatform Win32NT\r\nPSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}\r\nPSRemotingProtocolVersion 2.3\r\nSerializationVersion 1.1.0.1\r\nWSManStackVersion 3.0\r\n```\r\n","author":{"url":"https://github.com/rkeithhill","@type":"Person","name":"rkeithhill"},"datePublished":"2018-04-30T22:33:29Z","url":"https://github.com/PowerShell/PowerShell/issues/6780"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:c5c22178-9def-fcf2-8e37-64762b070b53 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8552:1C11C6:9BE77D:DFA93A:6AFD8ADF |
| html-safe-nonce | 173a3491f8309145b263a68ff98ecbff14b2a03ecff7286e178bdd66c074e463 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NTUyOjFDMTFDNjo5QkU3N0Q6REZBOTNBOjZBRkQ4QURGIiwidmlzaXRvcl9pZCI6IjM3NjI0MzY0MDMwMDI5Njg3OTkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 7473a635e5236b79aa8bfe31756fddd16dc6d9ef8c2875642874081d03aae728 |
| hovercard-subject-tag | issue:319058689 |
| 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/6780/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e18a2a1def7d17755ddb0b5b5db287f152266a4039fa8311afbc08bff16368d4/PowerShell/PowerShell/issues/6780 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e18a2a1def7d17755ddb0b5b5db287f152266a4039fa8311afbc08bff16368d4/PowerShell/PowerShell/issues/6780 |
| og:image:alt | This happens using the new -Form parameter that takes a hashtable of values and creates the multi-part form data. Steps to reproduce Find URL to webservice that accepts POST of multi-part form data... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | rkeithhill |
| hostname | github.com |
| expected-hostname | github.com |
| None | bc86424ef34a73b386237872800e922d149d65ba907f63d6f150a2dcb8433bea |
| 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 | 927a6c5ab1c32b38830f1b9d3050c0b9e9aa92e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width