【发布时间】:2015-03-02 07:40:19
【问题描述】:
嗨,我编写了这个脚本来获取网站的 html,但是我看到“无效请求”错误,但是当我创建一个 html 表单并提交它时,我没有问题,有什么问题吗?这是我的 php 代码:
<?php
$url = 'http://convert2mp3.net/en/index.php?p=convert';
$fields = array(
'url' => urlencode("www.youtube.com/watch?v=ntSBKPkk4m4"),
'format' => urlencode("3gp")
);
//url-ify the data for the POST
$fields_string="";
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_AUTOREFERER,true);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
?>
【问题讨论】: