我正在关注有关创建基于 javascript 的服务器/客户端环境的在线教程,为了测试 POST 方法,作者提供了一段 cURL 代码来运行。但是,当我尝试运行它时,出现错误。
我做了一些研究,我相当确定所提供的代码适用于 Linux 环境,但我在 Windows 10 上运行。我尝试将\
字符更改为,^
但仍然出现错误。我已经使用了 cmd 提示符和 PowerShell。
curl -X POST \
http://localhost:3000/signup \
-H 'Content-Type: application/json' \
-d '{
"email": "[email protected]",
"password": "1234",
"name": "test5"
}'
我希望代码将数据发布到我的数据库,但我得到以下输出:
C:\Users\ricks>curl -X POST \
curl: (6) Could not resolve host: \
C:\Users\ricks> http://localhost:3000/signup \
'http:' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\ricks> -H 'Content-Type: application/json' \
'-H' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\ricks> -d '{
'-d' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\ricks>"email": "[email protected]",
'"email":' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\ricks>"password": "1234",
'"password":' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\ricks>"name": "test5"
'"name":' is not recognized as an internal or external command,
operable program or batch file.
虽然提供的所有答案无疑都会使我能够运行我上面发布的 cURL 代码,但我找到了一种仅使用 Windows cmd 提示符的解决方法。
首先,我在一行而不是多行中编译了代码。其次,我发现编译错误主要来自未转义的"
字符。最后,以下代码正常工作并将数据发布到我的数据库!
curl -X POST http://localhost:3000/signup -H "Content-Type:application/json" -d "{\"email\" : \"[email protected]\", \"password\" : \"1234\", \"name\": \"test5\" }"
虽然这可能不是最可持续的方法,但对我来说这是一个很好的学习时刻,它可能会帮助那些希望利用一次性 cURL 执行而不向他们的系统下载任何额外内容的人。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句