如何让 cURL 代码在 Windows 10 上编译?

瑞克

我正在关注有关创建基于 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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在 Win 10 上从源代码编译 opencv

如何从 debian 10 上的源代码重新编译 dpkg?

如何在Linux上编译Windows Visual C ++代码

如何在Linux上正确调试交叉编译的Windows代码?

如何在Linux中编译C代码以在Windows上运行?

如何使用 Visual Studio 编译器在 Windows 上编译 cython 编译的 c 代码

据我所知,您无法在Windows上编译Swift,那么SwiftStub如何在Windows上编译代码?

如何在 Xampp Windows 10 上重新安装 PHP cURL?

如何在Windows x64上使用openSSL和nghttp2编译cURL?

在Windows 10上按“ Ctrl + C”按钮时,Python代码显示在屏幕上。如何隐藏此代码?

Mocha无法在Windows上编译Typescript代码

无法在NetBeans Windows上编译C代码

如何在 Windows 上编译和运行包含协程的 Kotlin 代码

如何在Windows 10上为代码块17.02指定MinGW64?

如何在 Windows 10 上为代码块 17.02 指定 MinGW64?

如何在Windows上更新cURL?

无法在Windows 10上编译PHP 5.6.12

C ++:如何在Windows 10上使用编译器MinGW 9.2.0安装OpenCV

如何在Windows 10中的VB6上编译Winsock Control 6.0?

如何在Windows-10上编译REDIS 5.0.5,make出错

如何使用 Python.h 和 MinGW 在 Windows 10 上编译调用 Python 方法的 C 文件

在Windows 10l中编译后,如何将openjdk9源代码导入Visual Studio 2017?

如何从github上的源代码进行编译?

如何从Shell上的cURL检索错误代码

在 Windows 10 中启用 cURL

如何使用GRUB更新CPU的微代码并加载Windows 10?

如何获得在 Windows 10 中运行 Python 代码的权限

如何使用Evince3源代码中的msys2在Windows上编译Evince3?

如何通过在Windows上使用cl.exe定义task.json以在vscode中编译C / C ++代码?