windows - Windows 10 上的 curl:“标题中的无效字符”
问题描述
我正在尝试在REST API Home Assistant Developer Docs的 Windows 10 上使用下面的 curl 示例。
curl -X POST -H "Authorization: Bearer ABCDEFGH" \
-H "Content-Type: application/json" \
-d '{"entity_id": "switch.christmas_lights"}' \
http://localhost:8123/api/services/switch/turn_on
下面是我的实际命令行(转义 Windows 的双引号):
curl -X POST -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiI5OTc5ZDUwZjA2MDk0YmQ1YTBkYjkyYmQ5MjEyYWZkNyIsImlhdCI6MTU4Nzc5MzI4NywiZXhwIjoxOTAzMTUzMjg3fQ.8sjGRXL1spXguuRnp795049zdCFcOtraCiDjC61UkWQ" -H "{\"Content-Type: application/json\"}" -d "{\"entity_id\": \"light.media_room_light\"}" http://homeassistant.local:8123/api/services/switch/turn_on
它以以下错误消息响应。我正在使用从中下载的 curl.exe
invalid character in header
我从以下网址下载curl.exe: https ://curl.haxx.se/windows/
解决方案
我认为您的 MIME Content-Type 标头与 json 编码数据字段混合在一起。
而不是这个:
-H "{\"Content-Type: application/json\"}"
这个:
-H "Content-Type: application/json"
扁平化为一行:
curl -X POST -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiI5OTc5ZDUwZjA2MDk0YmQ1YTBkYjkyYmQ5MjEyYWZkNyIsImlhdCI6MTU4Nzc5MzI4NywiZXhwIjoxOTAzMTUzMjg3fQ.8sjGRXL1spXguuRnp795049zdCFcOtraCiDjC61UkWQ" -H "Content-Type: application/json" -d "{\"entity_id\": \"light.media_room_light\"}" http://homeassistant.local:8123/api/services/switch/turn_on
推荐阅读
- python - Python ffmpeg 子进程制作无法播放的文件,但大小合适,只是挂起
- asp.net - 浏览到 ASP.NET 网站文件夹中的 PDF
- eclipse - 最终启动序列中的错误:无法执行 MI 命令:-exec-run
- python-3.x - 有人可以解释一下,以下代码段的输出如何为 100?
- networking - 我有一个关于流量控制数据的利用率和吞吐量以及如何找到数据包错误率的问题
- javascript - 以反应形式自定义验证器传递动态参数
- java - 当缺少一个 configurationPid 时,OSGi DS 的组件属性的优先级如何?
- nginx - 在 nginx-ingress-controller 上替换 Kubernetes Ingress Controller Fake Certificate fake
- r - 如何在r中输入矩阵的行,使得每行都是不同数字的幂
- python - 我如何在 python 演说家中搜索变形对象?