Php 向openfire发送用户服务请求
我正在使用codeigniter,我想向openfire发送一个添加请求,但我真的不明白我要做什么。我是一个初学者,我读了这本指南,我试图用curl添加一个新用户,但我被卡住了。Openfire的配置是正确的,因为如果我从浏览器发出请求,添加将起作用 这是我的密码Php 向openfire发送用户服务请求,php,codeigniter,curl,openfire,Php,Codeigniter,Curl,Openfire,我正在使用codeigniter,我想向openfire发送一个添加请求,但我真的不明白我要做什么。我是一个初学者,我读了这本指南,我试图用curl添加一个新用户,但我被卡住了。Openfire的配置是正确的,因为如果我从浏览器发出请求,添加将起作用 这是我的密码 $this->load->library('curl'); $username='usertest'; $password='password'; $header='Authorization'
$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='0
“.$user['username']”
“.$user['password']”
“.$user['name']”
“.$user['email']”
';
//开放连接
$ch=curl_init();
//设置url、POST变量数和POST数据
curl_setopt($ch,CURLOPT_URL,$URL);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_头,true);
curl_setopt($ch,CURLOPT_HTTPHEADER,数组(
“授权:机密”,
'内容类型:应用程序/xml'
));
卷曲设置($ch,卷曲设置桩,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$xml);
#curl_setopt($ch,CURLOPT_POSTFIELDSPOST,count($fields));
#curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
//执行职务
$result=curl\u exec($ch);
$http\u status=curl\u getinfo($ch,CURLINFO\u http\u代码);
ob_start();//外缓冲器
#echo“代码:$http_status |用户名:{$user['name']}\n”;
ob_end_flush();
//密切联系
卷曲关闭($ch);
如果($http_status==201){
返回true;
}
否则返回false;
您应该将内容类型和授权设置为标题中的数组。
而且您的XML内容看起来是错误的。这不仅仅是数组中的用户名/密码。请看一下第二部分:谢谢,借助本指南,不会再有错误,但不会添加用户,我认为autentication或post参数中有错误
$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;