首页 > 解决方案 > 使用 powershell 的最简单的 XML-RPC 查询示例?

问题描述

希望简化甚至“简化”此示例

$source = @'
namespace OpenSubtitlesAPI
{
    using CookComputing.XmlRpc;

    [XmlRpcUrl("http://api.opensubtitles.org/xml-rpc")]
    public interface IOpenSubtitles : IXmlRpcProxy
    {
        [XmlRpcMethod("LogIn")]
        XmlRpcStruct LogIn(string username, string password, string language, string useragent);

        [XmlRpcMethod("LogOut")]
        XmlRpcStruct LogOut(string token);

        [XmlRpcMethod("SearchSubtitles")]
        XmlRpcStruct SearchSubtitles(string token, XmlRpcStruct[] queries);

        [XmlRpcMethod("SearchSubtitles")]
        XmlRpcStruct SearchSubtitles(string token, XmlRpcStruct[] queries, int limit);
    }

    public class ProxyFactory
    {
        public static IOpenSubtitles CreateProxy()
        {
            return XmlRpcProxyGen.Create<IOpenSubtitles>();
        }
    }
}
'@

以便xml-rpc调用最简单的查询。Linux上使用 .NET Core 。

也在尝试:

所需的输出:

$VAR1 = {
          'description' => 'Mountain Dew',
          'upc' => '012000000850',
          'upce' => '01208500',
          'issuerCountryCode' => 'us',
          'noCacheAfterUTC' => bless( do{\(my $o = '2020-11-16T17:20:29')}, 'Frontier::RPC2::DateTime::ISO8601' ),
          'pendingUpdates' => '0',
          'issuerCountry' => 'United States',
          'ean' => '0012000000850',
          'size' => '12fl oz (355mL)',
          'found' => bless( do{\(my $o = '1')}, 'Frontier::RPC2::Boolean' ),
          'status' => 'success',
          'message' => 'Database entry found',
          'lastModifiedUTC' => bless( do{\(my $o = '2014-05-27T04:52:02')}, 'Frontier::RPC2::DateTime::ISO8601' )
        };

改编自以下示例脚本perl

#!/usr/bin/perl
#
# Get an RPC key assigned on the "Account Info" page on https://www.upcdatabase.com/
# Then substitute your own RPC key for $key below.
#
# Usage examples:
#   perl_example_new.pl test
#   perl_example_new.pl help
#   perl_example_new.pl lookup upc 012000000850
#   perl_example_new.pl lookup ean 0012000000850

use Frontier::Client;
use Data::Dumper;

use strict;

my $server_name = 'www.upcdatabase.com';

my $key = '445d...aa3';

my $server = Frontier::Client->new( 'url' => 'https://' . $server_name . '/xmlrpc', debug => 0, );

my $method = shift;

my $result = $server->call($method, { rpc_key => $key, @ARGV } );

print Dumper($result);

__END__

适应powershell使用REPL控制台:

PS /home/nicholas/powershell> 
PS /home/nicholas/powershell> Get-Help Send-XmlRpcRequest -Examples

NAME
    Send-XmlRpcRequest
    
SYNOPSIS
    Send a XML RPC Request
    
    
    -------------------------- EXAMPLE 1 --------------------------
    
    PS > Send-XmlRpcRequest -Url "example.com" -MethodName "updateName" -Params @('oldName', 'newName')
    ---------
    Description
    Calls a method "updateName("oldName", "newName")" on the server example.com
    

PS /home/nicholas/powershell> 
PS /home/nicholas/powershell> Send-XmlRpcRequest -Url "www.upcdatabase.com" -MethodName "012000000850" -Params @('fjkdlsfjd')
Exception: /home/nicholas/.local/share/powershell/Modules/XmlRpc/1.0.1.1/XmlRpc.psm1:323
Line |
 323 |              $doc.LoadXml($response)
     |              ~~~~~~~~~~~~~~~~~~~~~~~
     | Exception calling "LoadXml" with "1" argument(s): "Root element is missing."

PS /home/nicholas/powershell> 


    

或使用脚本文件。

标签: linuxpowershellmicroservicesxml-rpc

解决方案


推荐阅读