diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs index 435eafb79b8..bafa871187e 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs @@ -1817,7 +1817,8 @@ private void AddMultipartContent(object fieldName, object fieldValue, MultipartF private StringContent GetMultipartStringContent(Object fieldName, Object fieldValue) { var contentDisposition = new ContentDispositionHeaderValue("form-data"); - contentDisposition.Name = LanguagePrimitives.ConvertTo(fieldName); + // .NET does not enclose field names in quotes, however, modern browsers and curl do. + contentDisposition.Name = "\"" + LanguagePrimitives.ConvertTo(fieldName) + "\""; var result = new StringContent(LanguagePrimitives.ConvertTo(fieldValue)); result.Headers.ContentDisposition = contentDisposition; @@ -1833,7 +1834,8 @@ private StringContent GetMultipartStringContent(Object fieldName, Object fieldVa private StreamContent GetMultipartStreamContent(Object fieldName, Stream stream) { var contentDisposition = new ContentDispositionHeaderValue("form-data"); - contentDisposition.Name = LanguagePrimitives.ConvertTo(fieldName); + // .NET does not enclose field names in quotes, however, modern browsers and curl do. + contentDisposition.Name = "\"" + LanguagePrimitives.ConvertTo(fieldName) + "\""; var result = new StreamContent(stream); result.Headers.ContentDisposition = contentDisposition; @@ -1850,7 +1852,8 @@ private StreamContent GetMultipartStreamContent(Object fieldName, Stream stream) private StreamContent GetMultipartFileContent(Object fieldName, FileInfo file) { var result = GetMultipartStreamContent(fieldName: fieldName, stream: new FileStream(file.FullName, FileMode.Open)); - result.Headers.ContentDisposition.FileName = file.Name; + // .NET does not enclose field names in quotes, however, modern browsers and curl do. + result.Headers.ContentDisposition.FileName = "\"" + file.Name + "\""; return result; }