Skip to content
Merged
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 @@ -228,6 +228,11 @@ public InvokeMgGraphRequest()

internal bool ShouldCheckHttpStatus => !SkipHttpErrorCheck;

/// <summary>
/// Only Set Default Content Type (application/json) for POST, PUT and PATCH requests, where its not specified via `-ContentType`.
/// </summary>
private bool ShouldSetDefaultContentType => Method == GraphRequestMethod.POST || Method == GraphRequestMethod.PUT || Method == GraphRequestMethod.PATCH;

private static async Task<ErrorRecord> GenerateHttpErrorRecordAsync(
HttpMessageFormatter httpResponseMessageFormatter,
HttpRequestMessage httpRequestMessage)
Expand Down Expand Up @@ -606,10 +611,10 @@ private long SetRequestContent(HttpRequestMessage request, string content)

Encoding encoding = null;
// When contentType is set, coerce to correct encoding.
if (ContentType != null)
if (!string.IsNullOrWhiteSpace(ContentType))
{
// 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
// to encode the Body of the GraphRequest sent to the server. Default Encoding format
// would be used if Charset is not supplied in the Content-Type property.
try
{
Expand Down Expand Up @@ -661,7 +666,7 @@ private void FillRequestStream(HttpRequestMessage request)
{
GraphRequestSession.ContentHeaders[HttpKnownHeaderNames.ContentType] = ContentType;
}
else if (Method == GraphRequestMethod.POST)
else if (ShouldSetDefaultContentType)
{
GraphRequestSession.ContentHeaders.TryGetValue(HttpKnownHeaderNames.ContentType, out var contentType);
if (string.IsNullOrWhiteSpace(contentType))
Expand Down