【问题标题】:AS2Secure drops multipart/signed content-type from headersAS2Secure 从标头中删除多部分/签名的内容类型
【发布时间】:2015-12-23 20:38:08
【问题描述】:

我正在尝试使用 PHP 库 AS2Secure 接收 AS2 MDN。消息到达并解码得很好,但是当响应发出时,它会从Content-Type 中删除主要的“multipart/signed”值。

例如,这样的内容应该在主标题中以指定多部分消息:

Content-Type: multipart/signed; boundary="----=_Part_8f23d0b4-8a42-4946-9928-4d12d9f7fc66.63"; protocol="application/pkcs7-signature"; micalg=SHA1

但是,当多部分消息的响应发出时,我只在主标题中看到:

Content-Type: text/html; charset=UTF-8

这会在远程服务器中触发错误,它希望消息将其内容类型指定为多部分。

我在AS2MDN.php 中跟踪了将多部分内容类型剥离到此代码:

// TODO : replace with futur AS2MimePart to separate content from header
if (strpos($content, "\n\n") !== false) $content = substr($content, strpos($content, "\n\n") + 2);

如果我删除此代码,缺少的 Content-Type: multipart/signed 行会显示在正文中,但 Content-Type: text/html 仍会显示在标题中。

有什么想法吗?

【问题讨论】:

  • 这是来自合作伙伴系统的 MIME 标头,对吗?他们能改变吗?
  • 合作伙伴系统的 MIME 标头是 multipart/signed,他们希望得到类似的 multipart/signed 响应。然而,他们从我们的系统得到的多部分消息的响应是text/html。就像某些东西在输出时覆盖了内容类型的 mime 值。

标签: php content-type edi


【解决方案1】:

这是由 PHP Laravel 框架(处理应用程序的路由)在输出期间覆盖标头引起的。

AS2server.php 中的handle() 方法中更改此代码:

ob_end_clean();
// send headers
foreach ($mdn->getHeaders() as $key => $value) {
    $header = str_replace(["\r", "\n", "\r\n"], '', $key . ': ' . $value);
    header($header);
}

// output MDN
echo $mdn->getContent();

...到这个 Laravel 友好代码:

$headers = [];

foreach ($mdn->getHeaders() as $key => $value) {
    $headers[str_replace(["\r", "\n", "\r\n"], '', $key)] = str_replace(["\r", "\n", "\r\n"], '', $value);
}

return \Response::make($mdn->getContent(), 200, $headers); // Use native Laravel response.

...解决了问题!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-20
    • 2018-02-14
    • 2021-11-26
    • 2017-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-03
    相关资源
    最近更新 更多