【问题标题】:How to setup Postman to handle APIs from remote server如何设置 Postman 以处理来自远程服务器的 API
【发布时间】:2021-12-29 01:46:27
【问题描述】:

我的 django 服务器在 ssh 客户端 (ubuntu) 中运行,但我想在本地窗口机器中测试 api。我怎样才能做到这一点?

【问题讨论】:

  • 在邮递员中使用您的网络应用程序的 url / IP 地址,并使用所需的身份验证。如果您的 django 应用程序未托管,请运行 python manage.py 0.0.0.0:8000 ,并使用本地系统中的 IP
  • 你能详细说明一下吗,这是我第一次做这种东西。

标签: django ubuntu nginx ssh postman


【解决方案1】:

如果您的 Web 应用程序是托管的(具有类似的域名 http://www.stackoverflow.com) 使用邮递员中的网址。

如果您的 webapp 尚未部署在某些网络服务器(apacahe、nginx+gunicorn 等)中

在服务器IP中公开运行django应用程序如下

python manage.py runserver 0.0.0.0:8000  // make sure port 8000 is open or use an open port.

还可以使用以下命令(在 shell 中)找到您的 ubuntu 的 IP 地址

 ifconfig

使用你在邮递员(windows)中获得的IP地址

eg: if the IP address got is 90.101.111.25, 
API endpoint: api/user/
method : POST

在邮递员客户端

use the url: 90.101.111.25/api/user/
select method : POST
Next you need to provide the Authorization ( to make sure only guanine users access your API). 

在 postman 中选择 Authorization 选项卡,然后选择 Authorization ( Digest Auth, Basic, Token) 你的网络应用支持。

如果您使用令牌身份验证,请找到创建的(其中一个)用户的令牌,并在邮递员中使用它。

Select Headers and add the following
key: Authorization
value: Token:<space>the-token-generated-by-django-in-the-db

检查以下内容以在 django(django-rest) 中实现基于令牌的身份验证。

https://www.django-rest-framework.org/api-guide/authentication/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-27
    • 2013-10-14
    相关资源
    最近更新 更多