php - 代理后面的 curl 发布文件返回错误

标签 php post curl proxy

我正在尝试将图像文件发布到服务器。最初我在家里测试了没有代理的脚本,它运行良好。但是当我在大学里使用相同的脚本时,它会抛出一些错误。上传图片的函数如下

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-continue。

所以最后把它添加到我的选项中

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

一切正常。

关于php - 代理后面的 curl 发布文件返回错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6244578/

相关文章:

PHP 如何让我的表单输入包含根据数据库中的选择自动生成的数据

php - 如何使用 PHP 创建适用于 iOS 的 Web 服务?

php - 用另一个数据库的结果填充数据库?

Php Curl 添加参数

swift - 如何使用 github api 为仓库加注星标

php - 在php中对数据列表进行排序?

php - 插入用户ID和字段

JSF commandLink,POST和后退按钮

javascript - 理解javascript多维数组的问题

linux -/usr/local/ssl/lib/libcrypto.a : could not read symbols: Bad value