php - 为什么 VirusTotal 会返回此错误?

标签 php api curl

我正在尝试使用 VirusTotal 的公共(public) API 来扫描文件。这是我的代码:

$post_url = 'https://www.virustotal.com/vtapi/v2/file/scan';    

$filemime = exec("file -b --mime-type '$file_to_scan'");

$post = array('apikey' => $virustotal_api_key, 'file' => '@' . realpath($file_to_scan) . ';type=' . $filemime . ';filename=' . $name);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$post_url);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPHEADER,array('Expect:'));
$api_reply = curl_exec($ch);
curl_close($ch);

$api_reply_array = json_decode($api_reply, true);

每当我运行这段代码时,我都会收到以下错误:

[response_code] => 0
[verbose_msg] => Invalid submission format, the uploaded file must travel as a multipart MIME message, please review the documentation

我花了好几个小时试图解决这个问题,但就是行不通。谁能指出我正确的方向?

这是上面代码中$postprint_r:

[apikey] => xxx
[file] => @/absolute/path/to/file.exe;type=application/octet-stream;filename=file.exe

谢谢!

最佳答案

在 VirusTotal 自己的帮助下(荣誉,Karl)弄明白了。问题在于 PHP 5.6 如何更改 cURL。如果您使用的是 PHP 5.6,则需要添加:

curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);

关于php - 为什么 VirusTotal 会返回此错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35568769/

相关文章:

php - API 测试工具

xml - libcurl SSL证书验证

php - 删除字符串后的字符?

php - 在 Magento OnePage Checkout 中下订单失败

php - 将user_id添加到Session mysql中

curl - jira curl 解决问题

python - 在 Python 中复制 curl 协商连接(使用 kerberos auth)

php - mysql 没有在 wmp 中启动

php - 如何获得 Paypal 销售交易

reactjs - Jest 没有实现 window.alert()