我将使用ReactJs使用ejabberd开发一个聊天应用程序。我在服务器上安装了ejabberd。我从下面的链接中了解了API文档。
https://docs.ejabberd.im/developer/ejabberd-api/admin-api/#registered-users
在实现之前,我想尝试一下postman中的任何api。但是我没有从任何文档中获得API URL和主机名。
我的ejabberd服务器管理URL是http://192.168.5.242:5280/admin
另外,我希望使用https://www.npmjs.com/package/ejabberd。但是在这里我可以看到主机名的用法。
我尝试了这么多端口,而不是5280。但不是为我工作。
发布于 2019-01-11 10:05:22
但是我没有从任何文档中获得API URL和主机名。
您可以在ejabberd配置文件的“侦听”部分中定义端口号。例如,在我的例子中,我对mod_http_api使用了5282,路径/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的url将是http://192.168.5.242:5282/api
发布于 2019-01-15 19:16:58
作为一个示例调用,我使用这个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"]https://stackoverflow.com/questions/54125953
复制相似问题