| Autor | Zpráva | ||
|---|---|---|---|
| Pizdítko Profil * |
#1 · Zasláno: 11. 2. 2017, 12:37:09
Dobrý den,
dokázal by mi někdo poradit s XML - RPC ? Používám běžnou knihovnu xmlrpc gggeek.github.io/phpxmlrpc verze 4.0.0 Mám vytvořený jednoduchý server a klienta, kde na straně serveru mám nachystanou funkci a na straně klienta volání. Pokaždé mi to ale vrátí chybu (errno/errstr) že je špatný parametr/chybí.. Níže zasílám co vrací a server + klienta Server public function run(){
$this->methods = array(
"getData" => array(
"function" => "getData",
"signature" => array( ( PhpXmlRpc\Value::$xmlrpcInt )), // getData + ID ( int )
"docstring" => "Auth server - getData (with AUTH ID)."
),
);
//create server
$this->server = new PhpXmlRpc\Server($this->methods);
$this->server->setDebug(0);
$this->server->compress_response = false;
$this->server->exception_handling = "UTF-8";
}
public function getData(){
return PhpXmlRpc\Response( "hahaha", "string" );
}Klient public function send(){
$this->auth_id = 123456;
PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding = 'UTF-8'; // diakritika
$this->server_connect = new xmlrpc_client('/index.php', 'mujweb.cz', 80); // pripojeni k serveru
$params = array(new xmlrpcval($this->auth_id, 'int'));
$msg = new xmlrpcmsg('getData', $params); //zavolani getData s parametry -> auth_id (int)
$response = $this->server_connect->send($msg);
print_r($response); //toto mi vraci vysledek uvedeny níže
}Výsledek $response PhpXmlRpc\Response Object ( [val] => 0 [valtyp] => [errno] => 3 [errstr] => Incorrect parameters passed to method: No method signature matches number of parameters [payload] => [hdrs] => Array ( [date] => Sat, 11 Feb 2017 11:30:13 GMT [server] => Apache/2.4.10 (Debian) [vary] => Accept-Encoding [content-encoding] => gzip [content-length] => 201 [connection] => close [content-type] => text/xml;charset=UTF-8 ) [_cookies] => Array ( ) [content_type] => text/xml [raw_data] => HTTP/1.1 200 OK ) |
||
| juriad Profil |
Problém je na řádce:
"signature" => array( ( PhpXmlRpc\Value::$xmlrpcInt )), // getData + ID ( int ) "signature" => array( array( PhpXmlRpc\Value::$xmlrpcString, PhpXmlRpc\Value::$xmlrpcInt )), // string getData ( int ) Podívej se na definici signatury funkce findstate v phpxmlrpc.sourceforge.net/server.php?showSource=TRUE. |
||
| Pizdítko Profil * |
Díky za pomoc, na to jsem taky koukal.
Každopádně i když použiji "signature" => array( array( PhpXmlRpc\Value::$xmlrpcString, PhpXmlRpc\Value::$xmlrpcInt )), // string getData ( int ) tak je tady pořád stejný problém [errno] => 3 [errstr] => Incorrect parameters passed to method: No method signature matches number of parameters Teď když to mám takhle "getData" => array( "function" => "getData", "signature" => array( array( PhpXmlRpc\Value::$xmlrpcArray, PhpXmlRpc\Value::$xmlrpcInt )), // string getData ( int ) "docstring" => "Auth server - getData (with AUTH ID)." ), a posílám $params = array( new xmlrpcval($this->auth_id, 'int') );
$msg = new xmlrpcmsg('getData', $params);
$response = $this->server_connect->send($msg);Tak to vrací [errno] => 17 [errstr] => Internal server error: no function matches method Dále jsem si jen připravil funkci, kterou by to mělo volat, jen nevím, jak se dosazuje ' $m '. Tedy, abych získal přijatá data.. S tím RPC dělám poprvé, dík za pochopení a pomoc. public function getData($m){
$myexport = array();
$myexport['poslane_id'] = $m->getParam(0);
return PhpXmlRpc\Response( $myexport, "array" );
} |
||
|
Časová prodleva: 26 dní
|
|||
| JoinT Profil * |
#4 · Zasláno: 9. 3. 2017, 19:30:42
Server
public function run(){
function getData($req){
$sno = $req->getParam(0);
$snv = $sno->scalarval();
if($snv=='12345') $s='OK, nazdar';
else $s='Pa pa '.$snv;
return new PhpXmlRpc\Response(new Value($s));
}
$this->methods = array(
"getData" => array(
"function" => "getData",
"signature" =>array(array(Value::$xmlrpcString, Value::$xmlrpcString)),
"docstring" => "Auth server - getData (with AUTH ID)."
),
);
//create server
$this->server = new PhpXmlRpc\Server($this->methods, false);
$this->server->setDebug(0);
$this->server->compress_response = false;
$this->server->exception_handling = "UTF-8";
$this->server->service();
} |
||
|
Časová prodleva: 9 let
|
|||
0