问题
When I send postdata using curl, I want to send json and binary data together.
$RequestForm = array();
$RequestForm['snd'] = 'Sender';
$RequestForm['sndnm'] = 'SenderName';
$RequestForm['rcvs'] = 'Receivers';
$binary1 = file_get_contents('./test.pdf');
$binary2 = file_get_contents('./test.jpg');
$postbody = array(
'form' => json_encode($RequestForm),
'file[0]' => $binary1,
'file[1]' => $binary2
);
curl_setopt($http, CURLOPT_POST, 1);
curl_setopt($http, CURLOPT_POSTFIELDS, $postbody);
I want to enter binary data, not the path to the file.
I looked for various ways, but I couldn't solve them.
Is there a solution?
回答1:
you should not read the file contens to send file... directly pass the file using @ and realpath... like this
$postbody = array(
'form' => json_encode($RequestForm),
'file[0]' =>'@'.realpath('test.pdf'),
'file[1]' => '@'.realpath('test.jpg')
);
来源:https://stackoverflow.com/questions/64038388/php-i-want-to-send-json-and-binary-data-together-by-curl