Php 通过curl从secure POST请求下载CSV文件的内容

Php 通过curl从secure POST请求下载CSV文件的内容,php,curl,Php,Curl,我正在尝试下载一个文件,该文件是在HTTPS页面上按下POST按钮时生成的。我必须通过cookie的内容来显示我已登录,但我已经在同一网站的其他地方进行了测试,一切正常 我正在成功地生成POST请求以请求我需要的数据,并且我正在发送它,但是我从web服务器上什么也没有得到 这是我的密码: // Build header $header = array(); $header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,"

我正在尝试下载一个文件,该文件是在HTTPS页面上按下
POST
按钮时生成的。我必须通过cookie的内容来显示我已登录,但我已经在同一网站的其他地方进行了测试,一切正常

我正在成功地生成
POST
请求以请求我需要的数据,并且我正在发送它,但是我从web服务器上什么也没有得到

这是我的密码:

// Build header
$header = array();
$header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,";
$header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
$header[] = "Cache-Control: max-age=0";
$header[] = "Connection: keep-alive";
$header[] = "Keep-Alive: 300";
$header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
$header[] = "Accept-Language: en-us,en;q=0.5";
$header[] = "Pragma: ";
$header[] = "Content-Type: application/x-www-form-urlencoded";

// Now do transfer
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://domain/pathtoscript");

// Send referer to make this look real
curl_setopt($ch, CURLOPT_REFERER, $referer);

// And disguise ourselves as a browser
curl_setopt($ch, CURLOPT_USERAGENT, $agent);

// Return results as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

// Follow redirects
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_VERBOSE, 1);

// Now send post data
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);

// Define where we can store cookies
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieFile);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile);

// Sender header and permitted encodings
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_ENCODING, '');

// Actually do it !
$result = curl_exec ($ch);

curl_close ($ch);

// Show result in browser (should be CSV text file)
echo $result;
我做错了什么?我不想打开一个对话框来提示我保存文件,我只希望文件的内容在
$result
中,以便我以后在应用程序中解析它


提前谢谢

你不会归还任何东西。。。下载代码在哪里?(标题,回显结果…)能否显示发出POST请求的代码。您可能可以从我不久前编写的代码中获得一些帮助。所有POST参数都放在$postData变量中-该部分有效。我需要添加什么下载代码才能将响应放入$result变量?这是一个有用的例子@merlin2011-谢谢。我已经做了我认为我需要的更改(上面也进行了编辑),但没有成功:-(