php – 代理后面的curl post文件返回错误

前端之家收集整理的这篇文章主要介绍了php – 代理后面的curl post文件返回错误前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图将图像文件发布到服务器.最初我在家里没有代理测试我的脚本,它工作正常.但是当我在我的大学里使用相同的脚本时,它会抛出一些错误.上传图像的功能如下
function upload($filepath,$dir)

{
    $ch = curl_init();
    curl_setopt($ch,CURLOPT_HEADER,0);
    curl_setopt($ch,CURLOPT_VERBOSE,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,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-continue.

所以最后添加到我的选项

curl_setopt($ch,CURLOPT_HTTPHEADER,array('Expect:'));

一切正常.

原文链接:https://www.f2er.com/php/137559.html

猜你在找的PHP相关文章