使用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"}’
请指导。 谢谢。
答案 0 :(得分:0)
我通过删除标头之前的反斜杠并在数据中添加反斜杠来尝试了该命令。现在,此命令对我有用: curl -X POST localhost / api / register -H“接受:application / json” -H“内容类型:application / json” -d“ {\” name \“:\” Amir \“,\”电子邮件\“ :\“ abc@gmail.com \”,\“密码\”:\“ Amir123 \”,\“密码确认\”:\“ Amir123 \”}“