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

标签 javascript curl

我正在关注有关创建基于 javascript 的服务器/客户端环境的在线教程,为了测试 POST 方法,作者提供了一段要运行的 cURL 代码。然而,当我尝试运行它时,出现错误。

我做了一些研究,我相当确定提供的代码适用于 Linux 环境,但我在 Windows 10 上操作。我尝试将 \ 字符更改为 ^ 但我仍然收到错误。我使用了 cmd 提示符和 PowerShell。

curl -X POST \
  http://localhost:3000/signup \
  -H 'Content-Type: application/json' \
  -d '{
    "email": "test5@test.com",
    "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": "test5@test.com",
'"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 提示符的解决方法。

首先,我将代码编译为单行而不是多行。其次,我发现编译错误主要来自未转义的 " 字符。最终,以下代码正常工作并将数据 POST 到我的数据库!

curl -X POST http://localhost:3000/signup -H "Content-Type:application/json" -d "{\"email\" : \"test4@test.com\", \"password\" : \"1234\",  \"name\": \"test5\" }"

虽然这可能不是最可持续的方法,但这对我来说是一个很好的学习时刻,它可能会帮助那些希望利用一次性 cURL 执行而不需要向系统下载任何额外内容的人。

关于javascript - 如何在 Windows 10 上编译 cURL 代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57450726/

相关文章:

javascript - Google 通过 Reveal.js 实现分析目标

滚动时更改标题颜色的JavaScript

javascript - 如何允许倒带但禁用 html5-video 中的快进

json - Golang Chi 路由器不呈现响应负载 JSON

curl - php webpayments pro install.php 不工作

javascript - emacs 更好的 js 语法高亮

javascript - 未定义 knockout 变量 - 范围问题?

使用 cloudflare(完整 SSL)对服务器的 PHP curl post 请求有 SSL 错误和空白 SESSION Cookie

php - multi curl 一次无法处理超过 200 个请求

linux - 在 url 中使用通配符进行 curl