Skip to content

Body to Query Parameters in GET Requests with InvokeMgGraphRequest #437

Closed
@ryanspletzer

Description

@ryanspletzer

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. :)

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;
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions