【发布时间】:2014-12-31 03:49:26
【问题描述】:
我有用 php 编写的 REST API,我想用 phpunit 对其进行测试。
我这样写了测试,它可以工作,但响应体是空的。我用 fiddler 对其进行了测试,它发送响应正文。
对不起我的英语。
class ProgrammerControllerTest extends PHPUnit_Framework_TestCase
{
public function testPOST()
{
// create our http client (Guzzle)
$client = new Guzzle\Http\Client();
$response = $client->post("http://api.loc/v2/", array(
'headers' => "User-Agent: Fiddler\r\n" .
"Host: api.loc\r\n".
"Content-Type: application/x-www-form-urlencoded\r\n".
"Content-Length: 34\r\n",
'body' => array('kle' =>'sino','lat' => '41', 'long' => '69'),
));
var_dump($response);
}
}
【问题讨论】: