I've been looking online for a few days and haven't been able to find a good example of posting data using php, I downloaded http_pecl and have tried to use it
Could you please help me understand what is wrong with my code? I believe it is that I am sending the data wrong so the server cannot see it (The server is expecting data the way that jquery post sends it)
$headers = array('method' => 'POST','Content-type' => 'application/json','content'=>json_encode(array('api_key'=>'5675476','grant_type' => 'password', 'username' => '12345','password'=>'12345')));
$r = new HttpRequest('http:/zztestapi.com/api/v5/authorize?api_key=5675476&grant_type=password&username=12345&password=12345', HttpRequest::METH_POST);
$r->setHeaders($headers);
$r->setContentType = 'application/json';
//$r->setBody(json_encode(array('api_key'=>'5675476','grant_type' => 'password', 'username' => '12345','password'=>'password')));
//$r->addPostFields(array('api_key'=>'5675476','grant_type' => 'password', 'username' => '12345','password'=>'password'));
//$r->addRawPostData(json_encode(array('api_key'=>'9000000141','grant_type' => 'password', 'username' => '12345','password'=>'password')));
$r->setOptions(array('cookies' => array('lang' => 'de')));
echo $r->send()->getBody();
$r->send();
My goal is to get code that sends similar to a jquery post
$.ajax({
url: 'http://zztestapi.com/api/v5/authorize',
type: 'POST',
data: {"api_key":"5675476","grant_type":"password","username":"12345","password":"12345"},
dataType: 'application/json',
success: function(data) {
alert(data);
}
});