Php 如何使用CURL动态创建POST请求?

Php 如何使用CURL动态创建POST请求?,php,html,curl,Php,Html,Curl,我使用简单的DOM php解析器抓取了一个网站: <?php include 'domparse.php'; $html = file_get_html('http://oceanofgames.com/rebel-galaxy-free-download/'); foreach($html->find('form[action="http://oceanofgames.com/Cloud-VPS-Download.php"]') as $element) echo $el

我使用简单的DOM php解析器抓取了一个网站:

<?php
include 'domparse.php';
$html = file_get_html('http://oceanofgames.com/rebel-galaxy-free-download/');
foreach($html->find('form[action="http://oceanofgames.com/Cloud-VPS-Download.php"]') as $element) 
    echo $element;
?>
但是,我有很多这样的URL需要处理。如何编写php代码来隔离这些元素,然后使用CURL发出POST请求


我是PHP新手,如果您能保持简单,我将不胜感激:)

在CURL中使用POST的最简单方法是:

$url = 'https://example.com/resource';
$data = 'filename=Rebel_Galaxy.zip&filesize=2GB&id=85.25';

$ch = curl_init($url);                                                                      
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);                                                                  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                      
/*curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
        'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:35.0) Gecko/20100101 Firefox/35.0'
    )
);*/   

$server_output = curl_exec ($ch);

echo  $server_output;

我理解这部分。问题是您所谈论的$data必须从上面的html表单动态生成。我该怎么做?好的!为此,您可以使用正则表达式或DOM元素!例如,我假设您有输入名称,所以您只需要输入值,对吗?例如:输入。*?name=“filename”\svalue=“(.?)”
curl --data "filename=Rebel_Galaxy.zip&filesize=2GB&id=85.25" https://example.com/resource
$url = 'https://example.com/resource';
$data = 'filename=Rebel_Galaxy.zip&filesize=2GB&id=85.25';

$ch = curl_init($url);                                                                      
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);                                                                  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                      
/*curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
        'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:35.0) Gecko/20100101 Firefox/35.0'
    )
);*/   

$server_output = curl_exec ($ch);

echo  $server_output;