根据数据内容确定content-type
HTML
// <!DOCTYPE html>
// php
if (strpos(trim($content), '<!DOCTYPE html>') === 0) {
header('Content-type:text/html;charset=utf-8');
}
XML
// <?xml
// php
if (strpos(trim($content), '<?xml') === 0) {
header('Content-type:text/xml;charset=utf-8');
}
JSON
// [ || {
// php
if (in_array(substr(trim($content), 0, 1), ['[', '{'])) {
header('Content-type:application/json;charset=utf-8');
}
更多待补充...
${content}