最近在windows環境下的cmd中,使用curl測試post接口,總是報Failed to decode JSON object的錯誤。
同樣的命令在windows環境的git bash窗口中執行是好的。git bash可以模擬linux環境下一些命令的輸入效果。 特別是scp命令給linux上傳文件,或者從linux上下載文件件時很方便。
windows環境中,curl命令中的雙引號需要使用"\"來進行轉義。
例如,curl -v 127.0.0.1://test/pools -X POST -H "Content-Type: application/json" -d '{"message":"test"}'
要加上轉義:
curl -v 127.0.0.1://test/pools -X POST -H "Content-Type: application/json" -d '{\"message\":\"tes\t"}'