更新时间:2023-01-03 18:47:12
Your Invoke-WebRequest
is missing the ContentType
parameter, which is necessary when your Method
is set to a verb for sending data (such as Post
).
The purpose of the Content-Type field is to describe the data contained in the body fully enough that the receiving user agent can pick an appropriate agent or mechanism to present the data to the user, or otherwise deal with the data in an appropriate manner.
In your case, the parameter will be -ContentType "application/json"
. For example:
Invoke-WebRequest -Uri "https://sheets.googleapis.com/v4/spreadsheets/$sheet/values/Sheet1!A1:D2:append?valueInputOption=USER_ENTERED&access_token=$($token.access_token)" -Method Post -ContentType "application/json" -Body $json