<?php
$post_data = array(
'filename'=>new \CurlFile($uploadPath),
'jsondata'=> json_encode($params,JSON_UNESCAPED_UNICODE)
$toPdfApi='https://example.com/convert2PDF'
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL,$toPdfApi);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl,CURLOPT_BINARYTRANSFER,true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'multipart/form-data',
'application/x-www-form-urlencoded'));
curl_setopt($curl, CURLOPT_POSTFIELDS,$post_data);
$result = curl_exec($curl);
Then I convert it to bash shell command
curl -i -X POST -H "Content-Type: multipart/form-data" -H "Content-Type: application/x-www-form-urlencoded" --data-binary 'filename=@/root/test.txt' --data-binary 'jsondata={"fileName":"test","id":"xxx","backlink":"https://example.com/hello"}' https://example.com/convert2PDF
But the reponse result still not right
HTTP/1.1 200 OK
Date: Fri, 01 Jun 2018 14:41:37 GMT
Content-Type: application/x-www-form-urlencoded
Transfer-Encoding: chunked
Server: Jetty(9.4.5.v20170502)
error
Can someone help ? is it my covert bash shell right?
if I use the following command [replace -data-binary to -F ], I get the right status ,but from the php code I know I should add the CURLOPT_BINARYTRANSFER in bash curl ,otherwise the https://example.com/convert2PDF can not get the right post data.
curl -i -X POST -H "Content-Type: multipart/form-data" -H "Content-Type: application/x-www-form-urlencoded" -F 'filename=@/root/test.txt' -F 'jsondata={"fileName":"test","id":"xxx","backlink":"https://example.com/hello"}' https://example.com/convert2PDF
HTTP/1.1 100 Continue
HTTP/1.1 200 OK
Date: Fri, 01 Jun 2018 16:29:35 GMT
Content-Type: application/x-www-form-urlencoded
Transfer-Encoding: chunked
Server: Jetty(9.4.5.v20170502)
success
I want to get the reponse's status is 200 ,and the result is success in --data-binary mode ,What can I do to udpate my bash command ?