CURL POST:“Content-Disposition:form-data; ...”而不是普通的“var = val& ...”

时间:2015-10-23 06:46:08

标签: php post curl http-headers

我用curl发布数据,我希望服务器以格式“var = val& var1 = val1 ....”接收帖子数据,但不是我看到

------------------------------59265dfc9763
Content-Disposition: form-data; name="id"

123
------------------------------59265dfc9763
Content-Disposition: form-data; name="amount"

4
------------------------------59265dfc9763
Content-Disposition: form-data; name="create_date"

如果我从浏览器表单发布,则显示确定。

这是卷曲部分

    $header=array(
      'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12',
      'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
      'Content-Type: application/x-www-form-urlencoded; charset=UTF-8',
    );

    $process = curl_init($url);
    curl_setopt($process, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($process, CURLOPT_SSL_VERIFYHOST, FALSE);

    curl_setopt($process, CURLOPT_POST, count($tdata));
    curl_setopt($process, CURLOPT_POSTFIELDS, $tdata);
    curl_setopt($process, CURLOPT_FOLLOWLOCATION,true);
    curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
    $cookies_path = realpath($_SERVER['DOCUMENT_ROOT'] . '/../cookies/');
    curl_setopt($process,CURLOPT_COOKIESESSION, true );
    curl_setopt($process,CURLOPT_COOKIEFILE, $cookies_path . '/cookies.txt');
    curl_setopt($process,CURLOPT_COOKIEJAR, $cookies_path . '/cookies.txt');        
    curl_setopt($process, CURLOPT_HTTPHEADER, $header);

1 个答案:

答案 0 :(得分:0)

我将数组翻译成字符串并通过CURLOPT_POSTFIELDS

传递