响应不正常的大块

时间:2013-12-02 14:45:04

标签: http symfony

我的简单控制器:

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配置?

1 个答案:

答案 0 :(得分:1)

尝试使用JsonResponse对象。我知道它应该是相同的“但我在Firefox中看到了一些不同......