AppleScript 是否有与 REST API 交互的方式?
我意识到我可以
do shell script curl
Run Code Online (Sandbox Code Playgroud)
小智 5
我会使用 curl
do shell script "#curl script here"
Run Code Online (Sandbox Code Playgroud)
如果您需要帮助来获得正确的 curl 语句,我推荐postman,它确实可以帮助我生成正确的代码。但请记住,如果您有这些:"在前面放一个转义字符:\"。
因此,例如,如果我想做一个 POST 请求
https://api.widerstandsberechner.ch/api.php?firstcolor=red&secondcolor=orange&thirdcolor=yellow&fourthcolor=silver&hasFiveRings=0&resultInText=0
Run Code Online (Sandbox Code Playgroud)
AppleScript 看起来像这样:
do shell script "curl -X POST -H \"Cache-Control: no-cache\" \"https://api.widerstandsberechner.ch/api.php?firstcolor=red&secondcolor=orange&thirdcolor=yellow&fourthcolor=silver&hasFiveRings=0&resultInText=0\""
Run Code Online (Sandbox Code Playgroud)
当然,您可以轻松地将结果分配为一个值:
set res to do shell script "curl -X POST -H \"Cache-Control: no-cache\" \"https://api.widerstandsberechner.ch/api.php?firstcolor=red&secondcolor=orange&thirdcolor=yellow&fourthcolor=silver&hasFiveRings=0&resultInText=0\""
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助!
| 归档时间: |
|
| 查看次数: |
4054 次 |
| 最近记录: |