【问题标题】:Set encoding between PHP soap server and c# soap client在 PHP soap 服务器和 c#soap 客户端之间设置编码
【发布时间】:2011-11-23 10:57:41
【问题描述】:

我有一个发送 html 页面内容的 PHP SOAP 服务器(使用 nuSOAP 和 wsdl)。当然,可以使用不同的编码对 HTML 进行编码,这就是问题出现的时候。如果我使用 PHP SOAP 客户端,我可以像这样发送编码:

$clienteSOAP = new SoapClient ("http://test.mine.com/wsdl/filemanager?wsdl",
                               array ('encoding' => 'ISO-8859-15'));
$clienteSOAP->__soapCall ("Test.uploadHTML",
             array (file_get_contents ('/home/КОЛЛЕКЦИЯ_РОДНИК_ПРЕМИУМ.html')));

如果我输入了正确的编码,到目前为止从未失败过。但是当我使用 C# 客户端时,如何将编码放入 Web 服务请求中?在 C# 中,代码是:

          System.IO.StreamReader html = new System.IO.StreamReader (
                     "C:\\Documents and Settings\\КОЛЛЕКЦИЯ_РОДНИК_ПРЕМИУМ.html"
                     ,System.Text.Encoding.GetEncoding("iso-8859-15"));
          string contenido = html.ReadToEnd();
          html.Close();

          Test.FileManager upload = new Test.FileManager();
          string resultado = upload.TestUploadHTML (contenido);

Test.FileManager 是 wsdl 的 Web 引用,当我看到“上传 html”时,有些字符不正确。

提前致谢。

【问题讨论】:

    标签: c# php soap nusoap


    【解决方案1】:

    nusoap 内部使用 php 函数 xml_parser_create,仅支持:ISO-8859-1、UTF-8 和 US-ASCII。出于这个原因,这个库不能很好地与其他编码一起使用。伟大的 PacHecoPe...

    更新:就我而言,最好的选择是以原始编码读取存档并将其转换为 utf-8:

    System.IO.StreamReader html = new System.IO.StreamReader (
                     "C:\\Documents and Settings\\КОЛЛЕКЦИЯ_РОДНИК_ПРЕМИУМ.html"
                     ,System.Text.Encoding.GetEncoding("iso-8859-15"));
    
    string contenido = html.ReadToEnd();
    html.Close();
    
    System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
    byte[] bytes = System.Text.Encoding.UTF8.GetBytes (contenido);
    string contenidoUTF8 = encoder.GetString(bytes);
    
    upload.RequestEncoding = System.Text.Encoding.GetEncoding("UTF-8");
    
    Test.FileManager upload = new Test.FileManager();
    string resultado = upload.TestUploadHTML (contenidoUTF8);
    

    UPDATE2: 使用 UTF-8 不支持的编码,如 big5,上面的代码不能很好地工作。为此,最好不要转成UTF-8,在wsdl中用base64Binary之类的html内容设置参数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-07-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多