【问题标题】:How to show return values fom a PHP XML-RPC call?如何显示 PHP XML-RPC 调用的返回值?
【发布时间】:2020-08-03 08:20:43
【问题描述】:

我似乎找不到任何代码来显示调用返回的值。

我正在通过以下链接从软件供应商处运行 xml-lib

https://support.sippysoft.com/support/solutions/articles/3000013653-xml-rpc-api-sign-up-html-page-fresh-version-

<?php

include 'xmlrpc/xmlrpc.inc';


function listAccounts()
{
   //$params = array(new xmlrpcval(array("i_account"=> new xmlrpcval('14719', "string")), 'struct'));

    $msg = new xmlrpcmsg('listAccounts');

    /* replace here URL  and credentials to access to the API */
    $cli = new xmlrpc_client('https://DOMAINHERE/xmlapi/xmlapi');
    $cli->setSSLVerifyPeer(false);
    $cli->setSSLVerifyHost(false);
    $cli->setCredentials('USERNAME', 'PASSWORD', CURLAUTH_DIGEST);

    $r = $cli->send($msg, 20);
    if ($r->faultCode()) {
      error_log("Fault. Code: " . $r->faultCode() . ", Reason: " . $r->faultString());
      print_r ($r->faultString());
      return false;
    }
    else
    {
    return $r->value();

    // I need something here to write returned values to normal PHP variable

    }
}

【问题讨论】:

  • 你被否决了有几个原因 - A.) 你在大喊大叫 2.) 你的问题没有实际问题。
  • 我的道歉.. 编辑后的帖子
  • 我希望 XML-RPC 调用的值在 $r-&gt;value() 中。文档应该告诉您这是什么类型 - 字符串?一个东西?可以在退货前临时做echo gettype($r-&gt;value()); exit();,看看是什么类型。
  • 嗨..感谢您的回复,当我使用您的代码时它返回对象..

标签: php xml-rpc


【解决方案1】:

好的,感谢halfer的评论。

我设法解决了这个问题,并深入研究了库中的代码,我发现了一个可以解决问题的函数。

感谢您的指点,它确实有帮助。

我是 php 和 xml 新手,学习曲线非常高,但谢谢。

供其他人参考,也许将来这里是最后两行的更正代码,对我来说很神奇。

<?php
include 'xmlrpc/xmlrpc.inc';


        // $params = array(new xmlrpcval(array("offset"=> new xmlrpcval("1", "int")
        //                                ,"i_customer"=> new xmlrpcval("321", "int")
        //                                 ), 'struct'));

       $params = array(new xmlrpcval(array("i_customer"=> new xmlrpcval("321", "int")

                                           ), 'struct'));

       $msg = new xmlrpcmsg('listAccounts', $params);

       /* replace here URL  and credentials to access to the API */
       $cli = new xmlrpc_client('DOMAIN');
       $cli->setSSLVerifyPeer(false);
       $cli->setdebug(0);
       $r = $cli->send($msg, 20);       /* 20 seconds timeout */

       if ($r->faultCode()) {
         error_log("Fault. Code: " . $r->faultCode() . ", Reason: " . $r->faultString());
         echo $r->faultString();
       }

       // now lets decode the xml response..
        $values=php_xmlrpc_decode($r->value());
        var_dump ($values['accounts'][0][username]);

?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-09-10
    • 1970-01-01
    • 2012-02-16
    • 2013-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-02
    相关资源
    最近更新 更多