如何将Microsoft Graph Explorer的Preferred = Minimum标头转换为Powershell的Invoke-webrequest?

时间:2019-06-07 01:21:52

标签: microsoft-graph

如果我在Invoke-Webrequest中编写PowerShell代码以最小化响应,如何转换“ prefer = minimal”请求标头?

$Data = Invoke-WebRequest -Headers $authHeader -Uri $Url -Body $body -Method POST -UseBasicParsing -ContentType "application/json; charset=utf-8" -prefer "return=minimal"

此代码从我的角度来看不起作用。

PowerShell

1 个答案:

答案 0 :(得分:0)

Invoke-WebRequest不支持Prefer参数,而需要通过Headers参数来指定,例如:

$Url = "https://graph.microsoft.com/v1.0/users/delta?`$select=displayName,jobTitle,mobilePhone"
$headers = @{
    Authorization="Bearer $token"
    Prefer="return=minimal"
}

$Data = Invoke-WebRequest -Headers $headers -Uri $Url -Method GET -ContentType "application/json"