Hi, I´m now trying to create a simple PHP HTTP POST.
What am I doing wrong in this code to get it to work?

<?php $data = array('eventId' => 'fbf4a1a1-b4a3-4dfe-a01f-ec52c34e16e4', 'eventType' => 'event-type', 'data' => '{ a : 1 }', 'metadata' => '{ a : 1 }',); $json = json_decode($data, true); $r = new HttpRequest('', HttpRequest::METH_POST); $r->setOptions(array('http' => array('header' => 'Content-type: application/json', 'method' => 'POST', 'content' => http_build_query($json),))); $r->addPostFields(array('user' => 'mike', 'pass' => 's3c|r3t')); //$r->addPostFile('image', 'profile.jpg', 'image/jpeg'); try { echo $r->send()->getBody(); } catch (HttpException $ex) { echo $ex; } ?>

What does this do?

$json = json_decode($data, true);

Can you post the result?

What is the output of this code, it’s unlikely anyone has PHP installed to test it.


I get no result.

$json = json_decode($data, true);
I´m doing this because the data needs to be json when you are sending it to Event Store.
Am I doing wrong here?

The code executes without any problem. I´m using NetBeans and I have put the code into a PHP application project.

What is the contents of $json after running that function?

I don´t know. I´m no expert in PHP. That´s why I´m asking for help to get this HTTP POST to work.

My suspicion is that json_decode will deserialize json rather than serialise your structure into it.

Try using the netbeans debugger to inspect what the code is doing while it is running?

You want json_encode