SOAP服务中的哈希MD5不正确

时间:2015-10-23 00:45:34

标签: php web-services soap yii hash

我在yii有肥皂服务。我想将文件内容和文件内容哈希发送到soap服务,我需要检查content_hash是否已发送,content_hash是否与内容相同。我使用哈希函数作为MD5。我的问题是哈希内容总是不匹配。

nusoap客户端代码:

<?php
date_default_timezone_set('Pacific/Auckland');
// Pull in the NuSOAP code
require_once('./nusoap/lib/nusoap.php');
// Create the client instance
$client = new nusoap_client('http://localhost/my-project/web/handler', true);
$err = $client->getError();
if ($err) {
    // Display the error
    echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
    // At this point, you know the call that follows will fail
}
$proxy = $client->getProxy();

$content = file_get_contents('C:/TEST.txt');
$content_hash = md5($content);

$result = $proxy->getUpload("$content_hash", "$content");
print_r($result);
?>

Yii肥皂功能:

     /**
     * @param string $content_hash
     * @param string $content
     * @return string
     * @soap
     */

    public function getUpload($content_hash,$content){
        return $content_hash.'-----------'.md5($content);         
    }

功能正常,但两个哈希值都不同。任何线索?

1 个答案:

答案 0 :(得分:0)

我发现soap服务删除了Carriage Return,这使得它在服务器端成为一个不同的字符串,因为字符串是不同的哈希是不同的。我添加了以下内容来解决它:

$content = str_replace("\n", "\r\n", $content);

当我直接将所有内容放入变量时,它正在工作。

相关问题