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

<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 ''
'';
} 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

성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

AI Hentai Generator

AI Hentai Generator

AI Hentai를 무료로 생성하십시오.

뜨거운 도구

MinGW - Windows용 미니멀리스트 GNU

MinGW - Windows용 미니멀리스트 GNU

이 프로젝트는 osdn.net/projects/mingw로 마이그레이션되는 중입니다. 계속해서 그곳에서 우리를 팔로우할 수 있습니다. MinGW: GCC(GNU Compiler Collection)의 기본 Windows 포트로, 기본 Windows 애플리케이션을 구축하기 위한 무료 배포 가능 가져오기 라이브러리 및 헤더 파일로 C99 기능을 지원하는 MSVC 런타임에 대한 확장이 포함되어 있습니다. 모든 MinGW 소프트웨어는 64비트 Windows 플랫폼에서 실행될 수 있습니다.

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

WebStorm Mac 버전

WebStorm Mac 버전

유용한 JavaScript 개발 도구

ZendStudio 13.5.1 맥

ZendStudio 13.5.1 맥

강력한 PHP 통합 개발 환경

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기