Skip to content

Instantly share code, notes, and snippets.

@baywet
Created September 8, 2021 13:36
Show Gist options
  • Save baywet/33b6af6b40fe175324b27b534392ba52 to your computer and use it in GitHub Desktop.
Save baywet/33b6af6b40fe175324b27b534392ba52 to your computer and use it in GitHub Desktop.
AGS request payload compression test
$accessToken = "<AccessTokenWithMailSendPermission>"
$srcFileName = "PathToRequestPayloadUncompress-SeeOtherFile"
$destFileName = "APath"
$srcFileStream = New-Object System.IO.FileStream($srcFileName,([IO.FileMode]::Open),([IO.FileAccess]::Read),([IO.FileShare]::Read))
$destFileStream = New-Object System.IO.FileStream($destFileName,([IO.FileMode]::Create),([IO.FileAccess]::Write),([IO.FileShare]::None))
$gzip = New-Object System.IO.Compression.GZipStream($destFileStream,[System.IO.Compression.CompressionMode]::Compress)
$gzip.CopyTo($srcFileStream)
$gzip.Flush()
$destFileStream.Dispose()
Invoke-WebRequest -UseBasicParsing -Uri "https://graph.microsoft.com/v1.0/me/sendMail" `
-Method "POST" `
-Headers @{
"Authorization"="Bearer $accessToken"
"Accept"="*/*"
"Accept-Encoding"="gzip, deflate, br"
"Content-Encoding"="gzip"
} `
-ContentType "application/json" `
-InFile $destFileName
{"message":{"subject":"Meet for lunch?","body":{"contentType":"Text","content":"The new cafeteria is open."},"toRecipients":[{"emailAddress":{"address":"[email protected]"}}]}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment