I'm using CURL to get response from some webservice. Problem is that it need some POST data in format like this:
{
"type": {
"manufacturer": "AX",
"model": "AX",
"submodel": "AX"
}
}
My script looks like:
$url = 'URL';
// Initiate curl
$ch = curl_init();
// Disable SSL verification
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// Will return the response, if false it print the response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Set the url
curl_setopt($ch, CURLOPT_URL,$url);
// Execute
$result=curl_exec($ch);
// Closing
curl_close($ch);
// Will dump a beauty json :3
var_dump(json_decode($result, true));
I found a way how to use POST in CURL and it should looks like:
$fields = array(
'manufacturer' => urlencode('AX'),
'model' => urlencode('AY'),
'submodel' => urlencode('AZ')
);
curl_setopt($ch,CURLOPT_POST, $fields);
But this didn't work for me at all :(, always getting answer NULL. Please can somebody help me to figurate out what I'm doing wrong?
curl_setopt($ch,CURLOPT_POSTFIELDS, $yourArray)also check for errorsjson_encode($fields)instead of just$fields