@@ -228,6 +228,11 @@ public InvokeMgGraphRequest()
228
228
229
229
internal bool ShouldCheckHttpStatus => ! SkipHttpErrorCheck ;
230
230
231
+ /// <summary>
232
+ /// Only Set Default Content Type (application/json) for POST, PUT and PATCH requests, where its not specified via `-ContentType`.
233
+ /// </summary>
234
+ private bool ShouldSetDefaultContentType => Method == GraphRequestMethod . POST || Method == GraphRequestMethod . PUT || Method == GraphRequestMethod . PATCH ;
235
+
231
236
private static async Task < ErrorRecord > GenerateHttpErrorRecordAsync (
232
237
HttpMessageFormatter httpResponseMessageFormatter ,
233
238
HttpRequestMessage httpRequestMessage )
@@ -606,10 +611,10 @@ private long SetRequestContent(HttpRequestMessage request, string content)
606
611
607
612
Encoding encoding = null ;
608
613
// When contentType is set, coerce to correct encoding.
609
- if ( ContentType != null )
614
+ if ( ! string . IsNullOrWhiteSpace ( ContentType ) )
610
615
{
611
616
// If Content-Type contains the encoding format (as CharSet), use this encoding format
612
- // to encode the Body of the WebRequest sent to the server. Default Encoding format
617
+ // to encode the Body of the GraphRequest sent to the server. Default Encoding format
613
618
// would be used if Charset is not supplied in the Content-Type property.
614
619
try
615
620
{
@@ -661,7 +666,7 @@ private void FillRequestStream(HttpRequestMessage request)
661
666
{
662
667
GraphRequestSession . ContentHeaders [ HttpKnownHeaderNames . ContentType ] = ContentType ;
663
668
}
664
- else if ( Method == GraphRequestMethod . POST )
669
+ else if ( ShouldSetDefaultContentType )
665
670
{
666
671
GraphRequestSession . ContentHeaders . TryGetValue ( HttpKnownHeaderNames . ContentType , out var contentType ) ;
667
672
if ( string . IsNullOrWhiteSpace ( contentType ) )
0 commit comments