I am trying to send a cURL post request from my localhost, but I am getting Missing parameters error.When I try from REST client mozilla addon it is working fine. Below is my php code .
$file = tempnam(sys_get_temp_dir(), 'AMZREO');
$fh = @fopen($file, 'w+');
foreach($input as $curl_response)
{
fputcsv($fh, $curl_response, ',', '"');
}
// ... close the "file"...
@fclose($fh);
$post = array(
'file'=>'@'.$file
);
print_r($post);
$header[] = 'Authorization: Token '.$token;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$target_url.'?target='.$target);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
curl_setopt($ch, CURLOPT_HTTP200ALIASES, array(400, 500));
$response = curl_exec($ch);
Below is the response
print_r($response);
{"status": "Failure", "message": "Missing Parameters"}
And I am able to see created file in my temp folder. And when I print_r the $post array I am getting this result.
Array
(
[file] => @C:\Users\acer\AppData\Local\Temp\AMZEE93.tmp
)
Please help me in this regard.Any help would be greatly appreciated.