我正在尝试将图像文件发布到服务器。最初,我在家里测试了我的脚本,没有代理,效果很好。但当我在大学里使用同样的脚本时,却出现了一些错误。上传图像的功能如下
function upload($filepath,$dir)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_PROXY, 'localhost:7777');
curl_setopt($ch, CURLOPT_PROXYUSERPWD, 'ae07b026:kpack');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_URL, 'http://finalytics.in/sites/scrap/uploader.php' );
$post_array = array(
"my_file"=>"@".$filepath,
"upload"=>"Upload",
"dir"=>$dir
);
print_r($post_array);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_array);
$response = curl_exec($ch);
echo $response;
}
uploader.php是一个普通的文件,只保存图像。
我得到的错误就像这个
ERROR
The requested URL could not be retrieved
While trying to process the request:
POST /sites/scrap/uploader.php HTTP/1.1
Proxy-Authorization: Basic YWUwN2IwMjY6a3BhY2s=
User-Agent: Mozilla/4.0 (compatible;)
Host: finalytics.in
Accept: */*
Proxy-Connection: Keep-Alive
Content-Length: 87022
Expect: 100-continue
Content-Type: multipart/form-data; boundary=----------------------------07ae68105e71
The following error was encountered:
Invalid Request
Some aspect of the HTTP Request is invalid. Possible problems:
Missing or unknown request method
Missing URL
Missing HTTP Identifier (HTTP/1.0)
Request is too large
Content-Length missing for POST or PUT requests
Illegal character in hostname; underscores are not allowed
Your cache administrator is webmaster.
Generated Sun, 05 Jun 2011 17:26:33 GMT by proxy1.iitm.ac.in (squid/2.7.STABLE7)
问题是我们研究所使用的代理是"SQUID";。Squid不支持Expect:100继续。
所以最后把这个添加到我的选项中
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
一切都很好。
如果上述解决方案不起作用,请添加
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: multipart/form-data",'Expect: '));
我们有一个类似的错误,添加头Expect:
修复了我们的代理错误。然而,问题是卷曲本身的问题。版本<=7.68不起作用,版本>=7.70运行良好。