我正在尝试使用cURL从此站点获取结果。它只返回白页而不是下载链接。我的代码有什么问题?
这是我的代码
<?php
// Define URL where the form resides
$form_url = "http://www.tusfiles.net/83gjiu9h49nw";
// This is the data to POST to the form. The KEY of the array is the name of the field. The value is the value posted.
$data_to_post = array();
$data_to_post['op'] = 'download2';
$data_to_post['id'] = '83gjiu9h49nw';
$data_to_post['rand'] = 'utpaxiqp4ocv6krspq5geslurstt7z3bmvt5eqa';
$data_to_post['referer'] = '';
$data_to_post['method_free'] = '';
$data_to_post['method_premium'] = '';
$data_to_post['submit'] = 'Direct download link';
// Initialize cURL
$curl = curl_init();
// Set the options
curl_setopt($curl,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
curl_setopt($curl,CURLOPT_URL, $form_url);
// This sets the number of fields to post
curl_setopt($curl,CURLOPT_POST, sizeof($data_to_post));
// This is the fields to post in the form of an array.
curl_setopt($curl,CURLOPT_POSTFIELDS, $data_to_post);
//execute the post
$result = curl_exec($curl);
//close the connection
curl_close($curl);
?>
THX
答案 0 :(得分:0)
您可能需要对POST请求正文中的数据进行url编码。 所以而不是:
$data_to_post['submit'] = 'Direct download link';
你有:
$data_to_post['submit'] = urlencode('Direct download link');