下面的命令在命令行中运行正常。
curl -X POST "http://xxx.xx.xx.xx:xxxx/api/upload?id=123456" -H "accept: application/json" -H "Content-Type: multipart/form-data" -F "file=@a.pdf;type=application/pdf"
当我使用命令行在命令上方命中时,它会在返回响应中给出一个令牌。如果我也通过POSTMAN
调用,它会很好。
但是当我通过
PHP CURL它没有给出任何错误或令牌。我从POSTMAN
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "http://xxx.xx.xx.xx:xxxx/api/upload?id=123456",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => array('file'=> new CURLFILE('/C:/Users/User/Downloads/c.pdf')),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
?>
答案 0 :(得分:-2)
尝试将Content-Type: multipart/form-data
添加到您的请求中,例如
CURLOPT_HTTPHEADER => array('Content-Type: multipart/form-data')