json - cUrl 引发 JSON 格式错误但 Wget 不引发?
问题描述
我正在通过 Windows 上的批处理脚本发送 POST 请求。我手动安装了 wget,一切正常,但我想使用 cUrl,因为它最近成为 Windows 10 的标准功能,可以在其他较新的计算机上运行。问题是 cUrl 会引发 Json 格式错误,尽管似乎没有任何特殊字符异常。
我尝试将引号更改为撇号,反之亦然,并使用反斜杠和插入符号作为转义字符。这个 wget 脚本有效:
wget --quiet ^
--method POST ^
--header 'content-type: application/json' ^
--body-data '{"method":"passthrough", "params": {"deviceId": "[MyId]", "requestData": "{\"system\":{\"set_relay_state\":{\"state\":0}}}" }}' ^
--output-document ^
- 'https://eu-wap.tplinkcloud.com/?token=[MyToken]'
但是 cUrl 中完全相同的 JSON 被拒绝:
curl -X POST -H 'content-type:application/json' -d '{"method":"passthrough","params":{"deviceId":"[MyId]","requestData":"{\"system\":{\"set_relay_state\":{\"state\":0}}}"}}' https://wap.tplinkcloud.com?token=[MyToken]
感谢您的任何建议。
解决方案
- 您
C:\Windows\System32\curl.exe
在 Windows 的命令行上使用 Windows 10 中的 curl ( )。
如果我的理解是正确的,那么这个修改呢?
为 Windows 修改的 curl 命令:
curl -H "content-type:application/json" -d "{\"method\":\"passthrough\",\"params\":{\"deviceId\":\"[MyId]\",\"requestData\":\"{\\\"system\\\":{\\\"set_relay_state\\\":{\\\"state\\\":0}}}\"}}" https://eu-wap.tplinkcloud.com/?token=[MyToken]
- 在 Windows 命令行中,请使用双引号而不是单引号。
- 在 JSON 对象处,请转义每个双引号。
笔记:
- 我不确定您回复中的正确 URL。因此,请在进行上述测试时使用正确的 URL。
推荐阅读
- python - Python - 'NoneType' 对象不可下标(Steam 物品价格的小程序)
- arrays - 我怎么能从一个数组中只分离两个键和值..?
- javascript - 使用 js 检索线性渐变颜色 CSS
- ios - 如何减少 Firebase Analytics 的 Pod 依赖?
- java - 在通过 setVolume(0,0) 静音时保持 .isPlaying() 为真
- sas - SAS 宏:如何在不使用任何 proc 步骤的情况下使用 SAS 宏对“,”分隔的数字序列进行排序?
- amazon-athena - 我可以使用 Quicksight 可视化 Athena 的视图吗?
- python - 如何从字典列表中打印字典项目
- html - 当它转换到下一个项目时,如何修复 Iphone 上的 Bootstrap Carousel 闪烁/闪烁/闪烁?(包括视频示例)
- c++ - 使用 C++ 在 dm 脚本中加速霍夫变换算法