如何设置 Postman 来处理来自远程服务器的 API

How to setup Postman to handle APIs from remote server

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

If your web application is hosted ( have domain name like http://www.whosebug.com) use the url in your postman.

如果您的 webapp 还没有部署在某些网络服务器(apacahe、nginx+gunicorn 等)

运行 django应用在服务器公网IP如下

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

还可以使用以下命令(在 shell 中)

找到您的 ubuntu 的 IP 地址
 ifconfig

使用您在邮递员中获得的 ip 地址 (windows)

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). 

Choose Authorization tab in postman, and select the Authorization ( Digest Auth, Basic, Token) your web app supports.

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

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/