如果我在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"
此代码从我的角度来看不起作用。
答案 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"