【发布时间】:2021-04-26 07:04:24
【问题描述】:
我想将application/xml 输出为Content-Type 用于我的Slim 输出。下面你会看到我生成输出的代码。不幸的是,所有被注释掉的代码都不能输出相应的 Content-Type。你有什么建议吗?
<?php
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Factory\AppFactory;
use \Slim\Helper\Set;
require 'vendor/autoload.php';
use Psr7Middlewares\Middleware\TrailingSlash;
$app = AppFactory::create();
$app->get('/{show}/feed', function(Request $request, Response $response, $args) use($app) {
$html = '<?xml version="1.0" encoding="utf-8" ?><sampletag></sampletag>';
// $app->response->headers->set('Content-Type', 'application/xml');
// $response = $response->withHeader('Content-type', 'application/xml');
$response->getBody()->write($html);
// return $response->withStatus(201)->withHeader('Content-Type', 'application/xml')->getBody()->write($html);
return $response;
});
$app->run();
【问题讨论】: