powershell - PowerShell Discord Webhook
问题描述
使用此代码时出现错误
$uri = "https://discord.com/api/webhooks/760116538895499265/yhQdNc10asfDzt8hldAJp32et1Gp_1-mvqIGPWZiAMcOwFjb5aqf7uNEF7MX6i15UKJK"
$hash = @{ "content" = "heyyy"; }
$JSON = $hash | convertto-json
Invoke-WebRequest -uri $uri -Method POST -Body $JSON
Invoke-WebRequest : {"message": "Cannot send an empty message", "code": 50006}
At line:7 char:1
+ Invoke-WebRequest -uri $uri -Method POST -Body $JSON
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExc
eption
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
这是因为什么?
解决方案
您应该在请求中将 Content-Type 指定为 application/json:
Invoke-WebRequest -uri $uri -Method POST -Body $JSON -Headers @{'Content-Type' = 'application/json'}
请参阅:https ://github.com/discord/discord-api-docs/issues/1210
推荐阅读
- python - 将列表列表合并到数据框熊猫中
- c# - 使用 HttpClient 从 SOAP 发布请求中检索响应字段
- gcc - 如何禁用 Eigen 中内置函数的使用(它定义了该架构的 pikc 指令)
- reporting-services - 从客户端计算机加载 SSRS 2008 R2 报告时出现间歇性错误
- cors - 通过 Dropbox 服务 CSS 突然停止工作
- maven - gitlab-ci 和 maven 元数据
- php - 无法在 mysql 数据库中存储条带 webhook 数据
- c# - Unity DI - 使用构造函数解析接口
- php - 调用未定义的方法 Illuminate\Database\Query\Builder::dissociate()
- javascript - Js foreach 键=>值