0

我将使用 ReactJs 使用 ejabberd 开发一个聊天应用程序。我在我们的服务器上安装了 ejabberd。我遵循了以下链接中的 API 文档。

https://docs.ejabberd.im/developer/ejabberd-api/admin-api/#registered-users

在实施之前,我想在邮递员中尝试任何 api。但是我没有从任何文档中获取 API URL 和主机名。

我的 ejabberd 服务器管理 URL 是http://192.168.5.242:5280/admin

另外,我希望使用https://www.npmjs.com/package/ejabberd。但是在那里我可以看到主机名的用法。

我尝试了很多端口而不是 5280。但不适合我。

4

2 回答 2

0

作为一个示例调用,我使用这个 php 脚本:

<?php
$url='localhost:5282/api/registered_users/';
$login="key";
$password='secret';
$request=null;
$info=array(
            "host"=>"localhost"
           );
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($info));
$output=curl_exec($ch);
curl_close($ch);
print_r($output);
?>

这是查询的结果:

$ php test.php 
["user1","user2"]

嗅探网络流量,这是查询:

POST /api/registered_users/ HTTP/1.1
Host: localhost:5282
Accept: */*
Content-Length: 20
Content-Type: application/x-www-form-urlencoded

{"host":"localhost"}

这是回应:

HTTP/1.1 200 OK
Content-Length: 17
Content-Type: application/json
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Content-Type, Authorization, X-Admin

["user1","user2"]
于 2019-01-15T19:16:58.980 回答
0

但是我没有从任何文档中获取 API URL 和主机名。

您可以在 ejabberd 配置文件的“listen”部分中定义端口号。例如,在我的例子中,我使用 5282 作为 mod_http_api 和路径 /api:

  -
    port: 5282
    module: ejabberd_http
    request_handlers:
      "/api": mod_http_api
      "/bosh": mod_bosh
      "/oauth": ejabberd_oauth
      "/rest": mod_rest

我的 ejabberd 服务器管理 URL 是http://192.168.5.242:5280/admin

然后,如果您添加我拥有的行,您的 mod_http_api 网址将是http://192.168.5.242:5282/api

于 2019-01-11T10:05:22.483 回答