Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,23 @@ internal virtual void FillRequestStream(HttpRequestMessage request)
{
foreach (var entry in WebSession.ContentHeaders)
{
request.Content.Headers.Add(entry.Key, entry.Value);
if (SkipHeaderValidation)
{
request.Content.Headers.TryAddWithoutValidation(entry.Key, entry.Value);
}
else
{
try
{
request.Content.Headers.Add(entry.Key, entry.Value);
}
catch (FormatException ex)
{
var outerEx = new ValidationMetadataException(WebCmdletStrings.ContentTypeException, ex);
ErrorRecord er = new ErrorRecord(outerEx, "WebCmdletContentTypeException", ErrorCategory.InvalidArgument, ContentType);
ThrowTerminatingError(er);
}
}
}
}
}
Expand Down Expand Up @@ -1476,16 +1492,29 @@ internal long SetRequestContent(HttpRequestMessage request, string content)
// If Content-Type contains the encoding format (as CharSet), use this encoding format
// to encode the Body of the WebRequest sent to the server. Default Encoding format
// would be used if Charset is not supplied in the Content-Type property.
var mediaTypeHeaderValue = new MediaTypeHeaderValue(ContentType);
if (!string.IsNullOrEmpty(mediaTypeHeaderValue.CharSet))
try
{
try
var mediaTypeHeaderValue = new MediaTypeHeaderValue(ContentType);
if (!string.IsNullOrEmpty(mediaTypeHeaderValue.CharSet))
{
encoding = Encoding.GetEncoding(mediaTypeHeaderValue.CharSet);
}
catch (ArgumentException ex)
}
catch (FormatException ex)
{
if (!SkipHeaderValidation)
{
var outerEx = new ValidationMetadataException(WebCmdletStrings.ContentTypeException, ex);
ErrorRecord er = new ErrorRecord(outerEx, "WebCmdletContentTypeException", ErrorCategory.InvalidArgument, ContentType);
ThrowTerminatingError(er);
}
}
catch (ArgumentException ex)
{
if (!SkipHeaderValidation)
{
ErrorRecord er = new ErrorRecord(ex, "WebCmdletEncodingException", ErrorCategory.InvalidArgument, ContentType);
var outerEx = new ValidationMetadataException(WebCmdletStrings.ContentTypeException, ex);
ErrorRecord er = new ErrorRecord(outerEx, "WebCmdletContentTypeException", ErrorCategory.InvalidArgument, ContentType);
ThrowTerminatingError(er);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@
<data name="FormInFileConflict" xml:space="preserve">
<value>The cmdlet cannot run because the following conflicting parameters are specified: InFile and Form. Specify either InFile or Form, then retry. </value>
</data>
<data name="ContentTypeException" xml:space="preserve">
<value>The cmdlet cannot run because the -ContentType parameter is not a valid Content-Type header. Specify a valid Content-Type for -ContentType, then retry. To suppress header validation, supply the -SkipHeaderValidation parameter.</value>
</data>
<data name="CredentialConflict" xml:space="preserve">
<value>The cmdlet cannot run because the following conflicting parameters are specified: Credential and UseDefaultCredentials. Specify either Credential or UseDefaultCredentials, then retry.</value>
</data>
Expand Down
Loading