gpt4 book ai didi

php - 使用 PHP 调用 Python 网络服务

转载 作者:太空宇宙 更新时间:2023-11-04 06:24:39 25 4
gpt4 key购买 nike

Python Web 服务代码:

import web 
from soaplib.wsgi_soap import SimpleWSGISoapApp
from soaplib.service import soapmethod
from soaplib.serializers import primitive as soap_types

urls = ("/hello", "HelloService",
"/hello.wsdl", "HelloService",
)
render = web.template.Template("$def with (var)\n$:var")



class SoapService(SimpleWSGISoapApp):
"""Class for webservice """
@soapmethod(soap_types.String,_returns=soap_types.String)
def hello(self,message):
""" Method for webservice"""
return "Hello world "+message



class HelloService(SoapService):
"""Class for web.py """
def start_response(self,status, headers):
web.ctx.status = status
for header, value in headers:
web.header(header, value)


def GET(self):
response = super(SimpleWSGISoapApp, self).__call__(web.ctx.environ, self.start_response)
return render("\n".join(response))


def POST(self):
response = super(SimpleWSGISoapApp, self).__call__(web.ctx.environ, self.start_response)
return render("\n".join(response))

app=web.application(urls, globals())

if __name__ == "__main__":
app.run()

PHP 代码:

<?php

@ini_set("soap.wsdl_cache_enabled", "0");


$client = new SoapClient('http://localhost:8080/hello.wsdl');

echo("<pre>");
var_dump($client->__getFunctions());
echo("</pre>");
$params = array('World');


try {
print_r($client->__soapCall('hello', $params));

} catch (SoapFault $exception) {
echo $exception;
}
?>

当我运行我的 php 代码时,它会报告以下信息

SoapFault exception: [helloFault] hello() takes exactly 2 arguments (1 given) in C:\website\cosmetics\src\test02.php:15 Stack trace: #0 C:\website\cosmetics\src\test02.php(15): SoapClient->__soapCall('hello', Array) #1 {main}

如何解决这个问题?谢谢。

最佳答案

不确定 SoapClient 到底是什么,但看起来它需要另一个参数。文档怎么说?

关于php - 使用 PHP 调用 Python 网络服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9190115/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com