在窗口中使用 curl 的电报 API 抛出"message text is empty"错误



我正在运行以下命令,并收到下面的错误,说文本为空。但事实并非如此。我也试过POST,但它仍然会出现同样的错误。有什么想法吗?

curl.exe-khttps://api.telegram.org/bot0000:xxxxx/sendMessage?chat_id=333333&text=yooo

{"ok":false,"error_code":400,"description":"Bad Request:消息文本为空"}"text’未被识别为内部或外部命令,可操作程序或批处理文件。

您是如何让Curl在Windows中工作的?我的猜测是珍珠撞击黑客。好吧,这是我在过去做这件事时发现的。当你在Windows Powershell中使用Curl时,它并不知道如何处理内容。示例:当您进行API调用时;获取所有机器id";,您可能会得到一个包含100个值的列表。通常,您会对所需的名称执行类似"Grep"的操作,然后将"id"值传递给变量,并使用该值来影响目标。我发现发生的事情是,"text"字符串并不是作为字符串对象传递的,而是某种机器类型的对象。简而言之,你最终不得不转换数据,然后你必须想办法搜索它。它变得非常快。

解决方案:调用WebRequest

虽然这个模块需要一点时间来适应,但当你使用它时,你可以将值作为Powershell富对象传递,并使用每个人都喜欢的$variable.value语法。

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-webrequest?view=powershell-7.1

#chat_id variable creation. This might need to be in the header, I don't know this API but wanted to show the example 
$body = @{ 
chat_id = 333333
text = yooo 
} 
#Example. Actual code may vary. 
$message = @{Invoke-RestMethod "https://api.telegram.org/ `
- Headers @{Authorization = "bot0000 xxxxx"} `
- Body $body `
- Method  Get }
#now we can use $message to see what's available.
#we can then use $message.whatever to view the responses. 

相关内容

最新更新