【问题标题】:Testing Django API on a VPS with curl使用 curl 在 VPS 上测试 Django API
【发布时间】:2018-08-08 21:49:58
【问题描述】:

我正在尝试使用 curl 从本地终端访问我的 Django API 到 VSP

curl -H 'Accept: application/json; indent=4' -u admin:password http://127.0.0.1:8000/users/

所以,我尝试了很多方法,例如,

  • admin:password 替换为我的实际vps root@password
  • admin:password替换为我的实际数据库admin@password
  • http://127.0.0.1:8000 替换为我的vps url
  • 将端口8000替换为22,或808080

顺便说一句,我不知道我是否必须将 /users/ 更改为 /root/ 或其他任何东西。

我尝试了很多组合,但没有任何效果。 这是我正在测试的内容:http://www.django-rest-framework.org/tutorial/quickstart/#testing-our-api

如果重要的话,我的 vps 机器是 Debian 9 (Stretch)

想你的帮助

【问题讨论】:

标签: django curl django-rest-framework vps debian-stretch


【解决方案1】:

这对我有用:

curl -H 'Accept: applicatin/json; indent=4' -u [superuser username]:[superuser password] http://YOURVPSIPADDRESS/users/

admin:password 应该是您的 Django 站点上的超级用户用户名和密码,而不是您的数据库或 VPS 的用户名或密码。确保已在您的 VPS 上为您的 Django 站点创建了超级用户。

【讨论】:

  • 感谢您的回答。我收到此消息: curl: (56) Recv failure: Connection reset by peer 我之前收到过此消息,并在 Google 上搜索它,但仍然不知道它是 vps 设置还是我必须更正我的 curl 语法
  • 您是否尝试过确保您的 VPS 接受到端口 80 的连接?你用的是什么云服务器?
  • Inded,我的 VPS 没有防火墙,所以我激活了它,并允许端口 80(TCP 协议)。现在我收到了这条消息: curl: (7) Failed to connect to [ip address] port 80: Connection refused
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-05
  • 1970-01-01
  • 1970-01-01
  • 2016-08-19
  • 1970-01-01
相关资源
最近更新 更多