【发布时间】:2015-12-18 10:19:31
【问题描述】:
我已经用 PHPUnit 编写了测试,我想向服务器发送信息,我希望得到 json 响应。
我试图发送带有client->request 方法的'accept' => 'application/json' 标头作为第五个参数的第三个,但它不起作用。
我的代码:
class PostControllerTest extends WebTestCase
{
protected $client;
public function setUp()
{
self::bootKernel();
$this->client = static::createClient();
}
protected function testOK()
{
$this->client->request('GET', '/posts', [
'accept => 'application/json',
], [], [
'accept => 'application/json',
]);
}
}
但是如果我对谷歌浏览器的 RESTplugin 做同样的事情并发送这些标头,一切都可以。
我不知道有什么问题,因为理论上它应该有效。
【问题讨论】:
-
到底出了什么问题?您的客户端请求中是否出现错误,或者您是否收到类似
application/xml的结果? -
服务器返回正常的 html 站点。就像没有任何特殊的标题一样。
-
这里的答案是什么?