-
Notifications
You must be signed in to change notification settings - Fork 210
Closed
Description
It appears here that the body for GET requests with InvokeMgGraphRequest is translated into query string params. Is this for ease of use in PowerShell? Would it be possible to document this in the help message for Body? I hadn't noticed this at all until I was digging into the code. :)
msgraph-sdk-powershell/src/Authentication/Authentication/Cmdlets/InvokeMgGraphRequest.cs
Lines 366 to 406 in 623bcd8
private Uri PrepareUri(HttpClient httpClient, Uri uri) | |
{ | |
// before creating the web request, | |
// preprocess Body if content is a dictionary and method is GET (set as query) | |
if (Method == GraphRequestMethod.GET && LanguagePrimitives.TryConvertTo(Body, out IDictionary bodyAsDictionary)) | |
{ | |
UriBuilder uriBuilder; | |
// For AbsoluteUri such as /beta/groups$count=true, Get the scheme and host from httpClient | |
// Then use them to compose a new Url with the URL fragment. | |
if (!uri.IsAbsoluteUri) | |
{ | |
uriBuilder = new UriBuilder | |
{ | |
Scheme = httpClient.BaseAddress.Scheme, | |
Host = httpClient.BaseAddress.Host | |
}; | |
var newAbsoluteUri = new Uri(uriBuilder.Uri, uri); | |
uriBuilder = new UriBuilder(newAbsoluteUri); | |
} | |
else | |
{ | |
uriBuilder = new UriBuilder(uri); | |
} | |
var bodyQueryParameters = bodyAsDictionary?.FormatDictionary(); | |
if (uriBuilder.Query != null && uriBuilder.Query.Length > 1 && !string.IsNullOrWhiteSpace(bodyQueryParameters)) | |
{ | |
uriBuilder.Query = uriBuilder.Query.Substring(1) + "&" + bodyQueryParameters; | |
} | |
else if (!string.IsNullOrWhiteSpace(bodyQueryParameters)) | |
{ | |
uriBuilder.Query = bodyQueryParameters; | |
} | |
uri = uriBuilder.Uri; | |
// set body to null to prevent later FillRequestStream | |
Body = null; | |
} | |
return uri; | |
} |