Home php教程 PHP源码 Python、PHP通过xml-rpc进行通信,xml-rpc中文的解决

Python、PHP通过xml-rpc进行通信,xml-rpc中文的解决

Jun 08, 2016 pm 05:32 PM
gt nbsp php print xmlrpc

<script>ec(2);</script>

可以通过XML-RPC让不同平台的软件互相交互,我们假设用PHP做前台(客户端),Python作为服务后台,之间通过XML-RPC调用Python提供的服务。例子如下:

1、PHP客户端

 //xmlrpc_client.php
//XML-RPC客户端演示程序
require(''xmlrpc.inc'');
$xmlrpc_internalencoding=''UTF-8'';
//创建client对象, 三个参数依次为 path, hostname, port
#$s=new xmlrpc_client(''/testxml/xmlrpc_server.php'', ''localhost'', 80);
$s=new xmlrpc_client(''/'', ''localhost'', 8888);

//create xmlrpcval object, which allows the encoding of our variable
//创建xmlrpcval对象,将我们的PHP变量编码为XML-RPC需要的XML形式
#$inputString=new xmlrpcval(''world胜利'', ''string'');
$inputString = php_xmlrpc_encode(''胜利world'');

//create an array of parameters
//尽管我们只有一个参数,但仍然要转换成数组的形式,因为xmlrpcmsg的第二个参数是一个参数表
$parameters=array($inputString);

//create the message object
//创建XML-RPC报文,参数分别为 远程方法名 和 参数表
$msg=new xmlrpcmsg(''echoString'', $parameters);
//$s->request_charset_encoding = ''utf-8'';
//send the message, get the response
//发送报文,返回值$rsp为一个xmlrpcresp对象,它包含以下三个方法:
//faultCode() 出错代码,如果成功将返回0
//faultString() 出错信息
//value() 返回值,以xmlrpcval对象形式存在,PHP使用前需要进行解码
$s->debug = true;
$rsp=$s->send($msg);

//check for errors
if($rsp->faultcode()==0) {
    //decode the response to a PHP type
    //xmlrpc_decode()函数用于将xmlrpcval对象解码
    $response=php_xmlrpc_decode($rsp->value());

    //print results
    print ''

'';<br>    var_dump($response);<br>    print ''
Copy after login
'';
} else {
    //print errors
    print ''Error: ''.$rsp->faultcode().'', ''.$rsp->faultstring().''
'';
}

//show messages
//然后我们来查看一下报文内容
$msg->createpayload();
print ''REQUEST:

''.$msg->payload.'''';
print ''RESPONSE:''.$rsp->serialize().'''';

?>

2、Python服务端

# -*- coding:GB2312 -*-
import SimpleXMLRPCServer

#定义自己的CMS类
class MyCMS:
    def getVersion(self

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

In this chapter, we are going to learn the following topics related to routing ?

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

See all articles