我在使用 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": "[email protected]", "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": "[email protected]", "password": "toptal123", "password_confirmatio
n": "toptal123"}’
请指导。谢谢。
我通过在标题之前删除反斜杠并在数据中添加反斜杠在一行中尝试了该命令。现在这个命令对我有用: curl -X POST localhost/api/register -H "Accept: application/json" -H "Content-type: application/json" -d "{\"name\": \"Amir\ ", \"email\": \"[email protected]\", \"password\": \"Amir123\", \"password_confirmation\": \"Amir123\"}"
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句