我一直在努力使用ZF2将带有json的POST发送到Web服务。这就是我到目前为止所做的一切:
$array = array('nome' => 'cert123', 'certificado' => $cert);
$json = json_encode($array);
$request = new Request();
$request->getHeaders()->addHeaders([
'Content-Type' => 'application/json; charset=UTF-8'
]);
$request->setUri($this->uri);
$request->setMethod('POST');
$client = new Client();
$client->setAdapter('Zend\Http\Client\Adapter\Socket');
$client->setEncType(Client::ENC_FORMDATA);
$client->setRawBody($json);
$response = $client->dispatch($request);
if ($response->isSuccess()) {
echo "the post worked!";
} else {
echo "the post failed";
}
它总是失败,但我没有收到任何错误,网络选项卡中的POST请求一直在运行。任何想法将不胜感激。
TNX