SOAP/XML令牌从对象返回不可读字符。

huangapple go评论77阅读模式
英文:

SOAP/XML token returns unreadable characters from object

问题

在一个UTF-8的PHP页面上,我在阅读SOAP响应输出时遇到了问题。

这是我的代码:

<?php 
header('Content-Type:text/html; charset=UTF-8');
ini_set('display_errors','1');
error_reporting(E_ALL);
class loginInfo
{
    public $loginOperation= array(
        "loginId" => 'username',
        "password" => 'password',
        "thirdPartyId" => 'appname',
        "apiVersion" => '2'
    );
}


$client = new SoapClient("http:/example.com:9280/wsdl/test.wsdl", array('exceptions' => 0, 'trace' => 1,'encoding'=>'UTF-8'));

echo("<pre>");

$loginInfo = new loginInfo();
$response = $client->Login($loginInfo);
$data = $response->loginResult->loginSuccessData;
$primaryToken = $data->token->primary;
$secondaryToken = $data->token->secondary;
$expiration = $data->expiration;
var_dump($data); // 这个输出中的令牌字符串无法阅读
echo $primaryToken."\n"; //这一行内容混乱
echo htmlentities($primaryToken)."\n"; //这一行返回空白
echo "响应:\n" . htmlentities($client->__getLastResponse()). "\n";
?>

这是页面的响应文本。

object(stdClass)#5 (2) {
  ["token"]=>
  object(stdClass)#6 (2) {
    ["primary"]=>
    string(32) "Ȭ�h�����8��9����PӇ�k0$*���"
    ["secondary"]=>
    string(32) "p&#173;���z��5Y����Z�6�:�"
  }
  ["expiration"]=>
  string(24) "2020-01-04T08:37:06.835Z"
}
Ȭ�h�����8��9����PӇ�k0$*���

响应:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<tfm:loginResponse xmlns:tfm="http://www.example.com/test.xsd">
<tfm:loginResult>
<tfm:loginSuccessData>
<tfm:token>
<tcor:primary xmlns:tcor="http://www.example.com/exampleTypes.xsd">yKz/aKuGvZPFOK8e7A8508LT51DTh6JrMAEkAiqbkr4=</tcor:primary>
<tcor:secondary xmlns:tcor="http://www.example.com/exampleTypes.xsd">cMKtkAzwBZl6FsLkkzUHFwZZhx3U5xb7WhDjnTaZOqc=</tcor:secondary>
</tfm:token>
<tfm:expiration>2020-01-04T08:37:06.835Z</tfm:expiration>
</tfm:loginSuccessData>
</tfm:loginResult>
</tfm:loginResponse>
</soapenv:Body>
</soapenv:Envelope>

将令牌变量包装在HTML实体中会完全从页面中删除它。

我不太确定这是否与编码有关,因为据我所知,一切都应该是UTF-8。

英文:

On a utf-8 php page, I'm having trouble reading the output of a soap response.

This is my code:

&lt;?php 
header(&#39;Content-Type:text/html; charset=UTF-8&#39;);
ini_set(&#39;display_errors&#39;,&#39;1&#39;);
error_reporting(E_ALL);
class loginInfo
{
    public $loginOperation= array(
        &quot;loginId&quot; =&gt; &#39;username&#39;,
        &quot;password&quot; =&gt; &#39;password&#39;,
        &quot;thirdPartyId&quot; =&gt; &#39;appname&#39;,
        &quot;apiVersion&quot; =&gt; &#39;2&#39;
    );
}


$client = new SoapClient(&quot;http:/example.com:9280/wsdl/test.wsdl&quot;, array(&#39;exceptions&#39; =&gt; 0, &#39;trace&#39; =&gt; 1,&#39;encoding&#39;=&gt;&#39;UTF-8&#39;));

echo(&quot;&lt;pre&gt;&quot;);

$loginInfo = new loginInfo();
$response = $client-&gt;Login($loginInfo);
$data = $response-&gt;loginResult-&gt;loginSuccessData;
$primaryToken = $data-&gt;token-&gt;primary;
$secondaryToken = $data-&gt;token-&gt;secondary;
$expiration = $data-&gt;expiration;
var_dump($data); // token strings unreadable in this dump
echo $primaryToken.&quot;\n&quot;; //this line is garbled
echo htmlentities($primaryToken).&quot;\n&quot;; //This line returns blank
echo &quot;RESPONSE:\n&quot; . htmlentities($client-&gt;__getLastResponse()). &quot;\n&quot;;
?&gt;

And this is the response text from the page.

object(stdClass)#5 (2) {
  [&quot;token&quot;]=&gt;
  object(stdClass)#6 (2) {
    [&quot;primary&quot;]=&gt;
    string(32) &quot;Ȭ�h�����8��9����PӇ�k0$*���&quot;
    [&quot;secondary&quot;]=&gt;
    string(32) &quot;p&#173;���z��5Y����Z�6�:�&quot;
  }
  [&quot;expiration&quot;]=&gt;
  string(24) &quot;2020-01-04T08:37:06.835Z&quot;
}
Ȭ�h�����8��9����PӇ�k0$*���



RESPONSE:
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;soapenv:Envelope xmlns:soapenv=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
&lt;soapenv:Header/&gt;
&lt;soapenv:Body&gt;
&lt;tfm:loginResponse xmlns:tfm=&quot;http://www.example.com/test.xsd&quot;&gt;
&lt;tfm:loginResult&gt;
&lt;tfm:loginSuccessData&gt;
&lt;tfm:token&gt;
&lt;tcor:primary xmlns:tcor=&quot;http://www.example.com/exampleTypes.xsd&quot;&gt;yKz/aKuGvZPFOK8e7A8508LT51DTh6JrMAEkAiqbkr4=&lt;/tcor:primary&gt;
&lt;tcor:secondary xmlns:tcor=&quot;http://www.example.com/exampleTypes.xsd&quot;&gt;cMKtkAzwBZl6FsLkkzUHFwZZhx3U5xb7WhDjnTaZOqc=&lt;/tcor:secondary&gt;
&lt;/tfm:token&gt;
&lt;tfm:expiration&gt;2020-01-04T08:37:06.835Z&lt;/tfm:expiration&gt;
&lt;/tfm:loginSuccessData&gt;
&lt;/tfm:loginResult&gt;
&lt;/tfm:loginResponse&gt;
&lt;/soapenv:Body&gt;
&lt;/soapenv:Envelope&gt;

Wrapping the token variable in html entities completely removes it from the page when echoed.

Not entirely sure if this has to do with encoding, since as far as I am aware, everything should be in utf-8.

答案1

得分: 1

这些令牌看起来像Base64编码的二进制数据。SOAP客户端会自动识别并解码它(WSDL)。如果您希望将其输出为HTML/文本(用于调试),请以相同的方式进行编码:

echo base64_encode($primaryToken)."\n";
英文:

The tokens look like base64 encoded binary data. The SOAP client recognizes that (the WSDL) and decodes it automatically. If you like to output it in HTML/Text (for debugging) try encoding it the same way:

echo base64_encode($primaryToken).&quot;\n&quot;;

huangapple
  • 本文由 发表于 2020年1月6日 23:31:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/59614795.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定