php – 从nuSOAP webservice返回utf-8(波斯语)字符串

前端之家收集整理的这篇文章主要介绍了php – 从nuSOAP webservice返回utf-8(波斯语)字符串前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我写了一个非常简单的网络服务,你可以在下面看到它的代码

服务器:

@H_502_3@<?PHP ini_set('error_reporting',E_STRICT); require_once("nuSOAP/lib/nusoap.PHP"); $namespace = "http://localhost/webservice/index.PHP"; // create a new soap server $server = new soap_server(); $server->soap_defencoding = 'utf-8'; $server->decode_utf8 = false; // configure our WSDL $server->configureWSDL("HelloExample"); // set our namespace $server->wsdl->schemaTargetNamespace = $namespace; //Register a method that has parameters and return types $server->register( // method name: 'HelloWorld',// parameter list: array('name'=>'xsd:string'),// return value(s): array('return'=>'xsd:string'),// namespace: $namespace,// soapaction: (use default) false,// style: rpc or document 'rpc',// use: encoded or literal 'encoded',// description: documentation for the method 'Simple Hello World Method'); $POST_DATA = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : ''; // pass our posted data (or nothing) to the soap service $server->service($POST_DATA); exit(); ?>

客户:

@H_502_3@<!doctype html> <html> <head> <title>Title</title> <Meta charset="utf-8"/> </head> <body> <?PHP require_once("nuSOAP/lib/nusoap.PHP"); $client = new nusoap_client('http://localhost/webservice/index.PHP?wsdl'); $client->soap_defencoding = 'UTF-8'; $client->decode_utf8 = true; $err = $client->getError(); if ($err) { echo '<h2>Constructor error</h2><pre>' . $err . '</pre>'; die(); } $parameters = array('name' => "محمد"); $result = $client->call('HelloWorld',$parameters); if ($client->fault) { echo '<h2>Fault</h2><pre>'; print_r($result); echo '</pre>'; die(); } else { echo $result; } ?> </body> </html>

这应该返回Helloمحمد但是这个返回Hello ????

这是unicode问题吗?

任何帮助解决这个将不胜感激

我自己修理:)

用于服务器代码

@H_502_3@$server->soap_defencoding = 'UTF-8'; $server->decode_utf8 = false; $server->encode_utf8 = true;

并为客户代码

@H_502_3@$client->soap_defencoding = 'UTF-8'; $client->decode_utf8 = false;
原文链接:https://www.f2er.com/php/133570.html

猜你在找的PHP相关文章