使用curl将文件发布到第三方API

时间:2015-04-16 06:53:52

标签: php curl

我使用下面的代码将文件发布到第三方API -

$post = array('userName' => 'testabc','password'=>'testabc','FILE1'=>'abc.csv','cn'=>'10215');
        $fp = fopen("orders/abc.csv", 'r');

        $ch = curl_init("https://differentdomain.com/abc.cgi");

        curl_setopt($ch, CURLOPT_USERPWD, "myuser:mypwd");            
        curl_setopt($ch, CURLOPT_UPLOAD, 1);
        curl_setopt($ch, CURLOPT_TIMEOUT, 86400); 
        curl_setopt($ch, CURLOPT_INFILE, $fp);
        curl_setopt($ch, CURLOPT_NOPROGRESS, false);
        curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, 'CURL_callback');
        curl_setopt($ch, CURLOPT_BUFFERSIZE, 128);
        curl_setopt($ch, CURLOPT_INFILESIZE, filesize("orders/abc.csv"));
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        $suc = curl_exec ($ch);

        echo "==>".curl_error($ch);
        echo "-->".$suc; die;

返回500内部服务器错误。不确定我发布参数的方式是对还是错。

任何帮助表示感谢。

感谢。

1 个答案:

答案 0 :(得分:0)