http - 响应中格式错误的 block

标签 http symfony

我的简单 Controller :

class GeofencesController extends Controller
{
public function indexAction()

{
    $json = '[
    {
        "id": 123,
        "name": "muh",
        "latitude": 32.121456,
        "longitude": -19.238573,
        "radius": 500
    },
    {
        "id": 532,
        "name": "blah",
        "latitude": 32.121456,
        "longitude": -19.238573,
        "radius": 100
    },
    {
        "id": 720,
        "name": "bleh",
        "latitude": 32.121456,
        "longitude": -19.238573,
        "radius": 200
    }
]
';

$json = json_decode($json, true);
$response = new Response();
$response->setContent(json_encode($json));
$response->headers->set('Content-Type', 'application/json');
return $response;
}

给我一个格式错误的分块响应。例如在 java 中:

org.apache.http.MalformedChunkCodingException: Chunked stream ended unexpectedly

Chrome 拒绝显示响应,在 Firefox 中我可以看到响应并且 Fiddler2 检测到响应存在畸形。

编辑:

还试过:

class GeofencesController extends Controller
{
   public function indexAction()
   {
     $json = '[{"id": 123,"name": "bleh","latitude": 32.121456,"longitude": -19.238573,"radius": 500}]';
     $json = json_decode($json, true);
     $response = new JsonResponse($json);
     return $response;
   }

还是一样的问题。这有可能与 Apache 有关吗?还是 Symfony2 配置?

最佳答案

尝试使用 JsonResponse 对象。我知道它应该是一样的”,但我在 Firefox 中看到了一些差异......

关于http - 响应中格式错误的 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20331007/

相关文章:

以 UTF-8 编码的 JAVA Http POST 请求

mysql - Symfony2 学说通过 SSL 连接到数据库

php - Chrome 添加 "-, attachment"到下载的文件

symfony - FOS bundle - 如何选择具有特定角色的用户?

php - Guzzle HTTP客户端多线程下载文件 : EachPromises vs Pool objects

http - 在 Firefox 中禁用保持事件状态

symfony2 : multiple DB connections/entity managers with doctrine migrations & schema_filter

mysql - 使用 Symfony 手动连接 MySQL,无需 DBAL 或 ORM

http - IIS 不会同时向同一客户端发送两个响应(仅适用于 ASP)

c# - 通过 C# 连接 HTTP 方法