public static function getCanonicalHeaders($headers) { //如果没有headers,则返回空串 if (count($headers) == 0) { return ''; } $headerStrings = array(); foreach ($headers as $k => $v) { //跳过key为null的 if ($k === null) { continue; } //如果value为null,则赋值为空串 if ($v === null) { $v = ''; } //trim后再encode,之后使用':'号连接起来 $headerStrings[] = HttpUtil::urlEncode(strtolower(trim($k))) . ':' . HttpUtil::urlEncode(trim($v)); } //字典序排序 sort($headerStrings); //用'\n'把它们连接起来 return implode("\n", $headerStrings); }
public static function getCanonicalHeaders($headers) { if (count($headers) == 0) { return ''; } $headerStrings = array(); foreach ($headers as $k => $v) { if ($k === null) { continue; } if ($v === null) { $v = ''; } $headerStrings[] = HttpUtil::urlEncode(strtolower(trim($k))) . ':' . HttpUtil::urlEncode(trim($v)); } //Sort in alphabet order sort($headerStrings); //Catenate with '\n' return implode("\n", $headerStrings); }