【发布时间】:2019-01-23 04:03:38
【问题描述】:
我在使用 curl 时测试 laravel API 时遇到问题。 我正在关注教程https://www.toptal.com/laravel/restful-laravel-api-tutorial 当我在 CMD 上使用命令时,出现错误。 命令是:
curl -X POST localhost/api/register \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d '{"name": "John", "email": "john.doe@toptal.com", "password": "toptal123", "password_confirmation": "toptal123"}'
错误是:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta http-equiv="refresh" content="1;url=http://localhost" />
<title>Redirecting to http://localhost</title>
</head>
<body>
Redirecting to <a href="http://localhost">http://localhost</a>.
</body>
</html>curl: (6) Could not resolve host: \
C:\xampp\htdocs\top> -H "Accept: application/json" \
’-H’ is not recognized as an internal or external command,
operable program or batch file.
C:\xampp\htdocs\top> -H "Content-Type: application/json" \
’-H’ is not recognized as an internal or external command,
operable program or batch file.
C:\xampp\htdocs\top> -d ’{"name": "John", "email": "john.doe@toptal.com", "password": "toptal123", "password_confirmatio
n": "toptal123"}’
请指导。 谢谢。
【问题讨论】:
-
我认为 CMD 不会将反斜杠识别为行继续。您必须将所有内容放在一行中
-
一行使用,现在报错:{"name":["name field is required."],"email":["The email field is required."], “密码”:[“密码字段是必需的。”]}curl:(6)无法解析主机:John,curl:(6)无法解析主机:电子邮件 curl:(6)无法解析主机:toptal .com,curl:(6)无法解析主机:密码 curl:(6)无法解析主机:toptal123,curl:(6)无法解析主机:password_confirmation curl:(3)[globbing]不匹配的右括号/括号在第 10 列中