Http post返回zf2中包含无效字符的数据


Http post return data with invalid characters in zf2

Http post返回包含无效字符的数据

$url = 'https://sandbox.itunes.apple.com/verifyReceipt';
$params = array('receipt-data' => 'receipt data');
$params = json_encode($params);

我的代码是

 $client = new Client();
 $client->setUri($url);
 $client->setMethod('POST');
 $client->setRawBody($params);
 $client->setHeaders(array(
   'Content-Type: application/x-www-form-urlencoded; charset=UTF-8'
 ));
 $client->setAdapter(new Curl());
 $response = $client->send();
 $res      = $response->getContent();

我的输出是这个

����

如果有人知道这件事,请帮帮我。

您必须解码来自主体的JSON响应,如下所示:

var_dump(json_decode($response->getBody(), true));

然后你会得到一个正确响应的数组:)

例如:

array(1) { ["status"]=> int(21002) }