我正在尝试使用cURL使用内容类型为application / octet-stream的PUT上传文件,但即使我使用curl_setopt设置它,内容类型也总是'text / html'。我已经在firefox和chrome中进行了测试,看看它是否是浏览器怪癖或其他东西(它不是)所以我不知道我能做些什么。
error_reporting(E_ALL);
ini_set('display_errors', 1);
$ch = curl_init();
$localfile = 'upload.txt';
$fp = fopen($localfile, 'r');
curl_setopt($ch, CURLOPT_URL, $url.$localfile.'?type=file');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("content-type: application/octet-stream"));
curl_setopt($ch, CURLOPT_UPLOAD, 1);
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile));
curl_setopt($ch, CURLOPT_USERPWD, $un.":".$pw);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$msg = curl_exec ($ch);
$error_no = curl_errno($ch);
$print = curl_getinfo($ch);
curl_close ($ch);
if ($error_no == 0) {
$error = 'File uploaded succesfully.';
} else {
$error = 'File upload error.';
}
感谢阅读。