【问题标题】:openfire rest api get request is emptyopenfire rest api 获取请求为空
【发布时间】:2015-11-16 22:46:01
【问题描述】:

我有 XMPP 服务器 openfire。 我还添加了“rest api 插件”并使用 Chrome 工具“Postman”对其进行了测试,效果很好。

请求:

http://myhost.net:9090/plugins/restapi/v1/users

标题:

Authorization:myPasswort

结果:

{
  "user": [
    {
      "username": "admin",
      "name": "Administrator",
      "email": "info@admin.de",
      "properties": null
    },
  ...

现在我想在 appgyver.com 的作曲家应用程序中使用结果。相同的输入,但始终是服务器结果:

响应码:500。{"error":"Internal server error."}

然后我尝试使用 php 脚本获取请求:

$url = "myhost.net/plugins/restapi/v1/users";

$options = array(
    'http' => array(
        'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
        'Authorization' => 'myPasswort'
    ),
);
$context  = stream_context_create($options);
var_dump($http_response_header);
echo "\r\n";
$result = file_get_contents($url, false, $context);
var_dump($result);

结果:NULL bool(false)

我做错了什么? 谢谢

【问题讨论】:

    标签: php rest xmpp openfire


    【解决方案1】:

    用follow php sn-p试试吧:

        <?php 
          $url = "http://localhost:9090/plugins/restapi/v1/users";
          $curl = curl_init($url);
          curl_setopt($curl, CURLOPT_HEADER, false);
          curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
          curl_setopt($curl, CURLOPT_HTTPHEADER, array("Accept application/json", "Authorization: PehtV8mbAm5M5MM0"));
          curl_setopt($curl, CURLOPT_POST, true);
          curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET");
          $json_response = curl_exec($curl);
          $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
          echo $json_response;
          curl_close($curl);
       ?>
    

    只需更改您的 URL 和授权密钥即可。

    【讨论】:

      猜你喜欢
      • 2018-03-15
      • 2021-07-07
      • 2019-05-20
      • 2016-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多