douba3378 2014-01-15 04:03
浏览 64

php设置soap服务器响应的编码类型

I have created a soap server in php using the native soap server class in php. The encoding I need is ISO-8859-1. I have tried to do it while creating the soap server like this:

$server = new SoapServer('./AdviseAndPay.wsdl',array('encoding'=>'ISO-8859-1'));

However the encoding for the http header and the soap response is still utf-8.

I am returning a native php SoapVar object for the soap response. I have tried setting the header Content type to ISO-8859-1 with this code:

header('Content-Type: text/xml;charset=iso-8859-1') just before returning the SoapVar. However I still get the encoding as utf-8 in both the http header and the soap response.

I have tried answers in stackoverflow and in the answer the encdoding type has been set while defining the soap server but this has not worked for me.

Could you please help me. Thanks in advance.

Edit: This is the raw http response for the soap server response.

HTTP/1.1 200 OK
Date: Wed, 15 Jan 2014 04:47:16 GMT
Server: Apache/2.2.22 (Ubuntu)
X-Powered-By: PHP/5.4.9-4ubuntu2.4
Cache-Control: no-store, no-cache, must-revalidate, private, max-age=0
Pragma: no-cache
Expires: Wed, 11 Jan 1984 05:00:00 GMT
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 225
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/xml; charset=utf-8

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body><ns2:responseType xmlns:ns2="http://tempuri.org/response">
<code>00</code>
<message>incorrect username/password</message>
<responseBody>
<responseStr>5</responseStr>
</responseBody>
</ns2:responseType>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Edit:

I found that there was a php bug report regarding the encoding type of the soap server response. The latest comment on that saying there was a bug was in 2008. Here is the link: php bug

Could anyone verify if they have a similar problem with soap server encoding?

  • 写回答

1条回答 默认 最新

  • doubei5310 2014-01-15 18:07
    关注

    Make sure you don't cache those WSDL files thats mandatory while developing.

    ini_set( 'soap.wsdl_cache_enabled', '0' );
    

    The following configuration works for me.

    // Run SOAP Server
    ini_set( 'soap.wsdl_cache_enabled', '0' );
    $soap_config = array( 'encoding' => 'ISO-8859-1' );
    $soapserver = new SoapServer( 'soap.wsdl', $soap_config );
    ...
    
    // Create SOAP client
    $soap_client = new SoapClient( 'soap.wsdl', array( 'encoding' => 'ISO-8859-1', 'cache_wsdl' => WSDL_CACHE_NONE) );
    
    评论

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集