休息apigility中不需要的响应文本

时间:2015-05-07 12:11:01

标签: php zend-framework2 apigility

使用apigility来获取邮递员的json响应 当我在邮递员发送邮件请求并返回响应时

{
"\u0000*\u0000version": null,
"\u0000*\u0000contentSent": false,
"\u0000*\u0000recommendedReasonPhrases": {
    "100": "Continue",
    "101": "Switching Protocols",
    "102": "Processing",
    "200": "OK",
    "201": "Created",
    "202": "Accepted",
    "203": "Non-Authoritative Information",
    "204": "No Content",
    "205": "Reset Content",
    "206": "Partial Content",
    .
    .
    .
    "508": "Loop Detected",
    "511": "Network Authentication Required"
},
"\u0000*\u0000statusCode": 200,
"\u0000*\u0000reasonPhrase": null,
"\u0000*\u0000headers": {},
"\u0000*\u0000metadata": [],
"\u0000*\u0000content": "{\"success\":\"this is test\"}",
"_links": {
    "self": {
        "href": "http://xxxxx/xxxxx/public/userapi"
    }
}

我在userapiresource.php中的代码,使用get表数据并返回它也像这样输出

public function create($data)
{
    $response=new HttpResponse;
    $response->setContent(\Zend\Json\Json::encode(array('success'=>"this is test")));
    return $response;
 }

1 个答案:

答案 0 :(得分:0)

在apigility得到它的回应: 所以在userapiResource.php中更改我的代码

public function create($data)
{
$client = new Client();
    $client->setUri('http://xxxx/xxxx/public/mob-app/client/update');
    // set some parameters
    $client->setParameterPost(array('userid'=> $data->userid,'price'=>$data->price));
    // POST request
    $client->setMethod('POST');
    $respons=$client->send();

    $respons->getContent();
    $returnArray = [];

$final_array = [
    'content' => json_decode($respons->getContent())
     ];

$returnArray['data'] = $final_array;
$returnArray['success'] = 'true';
$returnArray['reason']  = '';


return $returnArray;
}