向 openfire 发送用户服务请求

Send userservice request to openfire

我正在使用 codeigniter,我想向 openfire 发送一个添加请求,但我真的不明白我必须做什么。我是初学者,我阅读了本指南 User Service and i tried to add a new user with curl Curl lib,但我被卡住了。 Openfire 已正确配置,因为如果我从浏览器发出请求,添加工作 这是我的代码

  $this->load->library('curl');
    $username='usertest';
    $password='password';
    $header='Authorization';
    $content='mykey';
    $this->curl->create('http://myserver.net', 9090);
    $this->curl->http_header($header, $content);
    $this->curl->http_header('Content-Type', 'application/xml');
    $this->curl->post(array('username'=>$username,'password'=>$password)); 
    $this->curl->execute();

但是没有添加用户

对不起我的英语不好

这是用户服务客户端的一种实现(它基于 Curl 而不是基于 codeigniter):

 $url = "http://localhost:9090/plugins/userService/users";
  $xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  <user>
     <username>'.$user['username'].'</username>
     <password>'.$user['password'].'</password>
     <name>'.$user['name'].'</name>
     <email>'.$user['email'].'</email>
  </user>';



  //open connection
  $ch = curl_init();


  //set the url, number of POST vars, POST data
  curl_setopt($ch,CURLOPT_URL, $url);
  curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
  curl_setopt($ch,CURLOPT_HEADER,true);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array(
     'Authorization: secret',
     'Content-Type: application/xml'
  ));
  curl_setopt($ch, CURLOPT_POST,           1 );
  curl_setopt($ch, CURLOPT_POSTFIELDS,     $xml );
  #curl_setopt($ch,CURLOPT_POSTFIELDSPOST, count($fields));
  #curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);


  //execute post
  $result = curl_exec($ch);
  $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  ob_start(); // outer buffer
  #echo "Code: $http_status | Username: {$user['name']}\n";
  ob_end_flush();
  //close connection
  curl_close($ch);

  if ($http_status == 201) {
  return true;
  }
  else return false;

您应该在 header 中将内容类型和授权设置为数组。 而且您的 XML 内容看起来不对。它不仅是数组中的用户名/密码。