在php中使用参数请求URL
我想为从下拉列表中选择的特定选项请求特定网页内容 在我的示例中,我想要来自web页面的内容,其中Community和Level是两个下拉列表。我需要选项在php中使用参数请求URL,php,curl,Php,Curl,我想为从下拉列表中选择的特定选项请求特定网页内容 在我的示例中,我想要来自web页面的内容,其中Community和Level是两个下拉列表。我需要选项Community='SoftwareFactory/Cloude'和Level='V6R2015x'的网页 我的代码是 <?php // init the resource $ch = curl_init('http://e4allds/'); // set a single option... $postData = array(
Community='SoftwareFactory/Cloude'
和Level='V6R2015x'
的网页
我的代码是
<?php
// init the resource
$ch = curl_init('http://e4allds/');
// set a single option...
$postData = array(
'Community' => 'SoftwareFactory/Cloud',
'Level' => 'V6R2015x'
);
curl_setopt_array(
$ch, array(
CURLOPT_URL => 'http://e4allds/',
CURLOPT_POSTFIELDS => $postData,
//OPTION1=> 'Community=SOftwareFactory/Cloud',
//OPTION2=> 'Level=V6R2015x',
CURLOPT_RETURNTRANSFER => true
));
$output = curl_exec($ch);
echo $output;
您需要将cURL
POST参数启用为true
curl_setopt_array(
$ch, array(
CURLOPT_POST => true, //<------------ This one !
CURLOPT_URL => 'http://e4allds/',
CURLOPT_POSTFIELDS => $postData,
//OPTION1=> 'Community=SOftwareFactory/Cloud',
//OPTION2=> 'Level=V6R2015x',
CURLOPT_RETURNTRANSFER => true
));
curl\u setopt\u数组(
$ch,数组(
CURLOPT_POST=>true,/'http://e4allds/',
CURLOPT_POSTFIELDS=>$postData,
//选项1=>“社区=软件工厂/云”,
//选项2=>“级别=V6R2015x”,
CURLOPT_RETURNTRANSFER=>true
));
根据,CURLOPT_POSTFIELDS
选项是要在HTTP“post”操作中发布的完整数据
因此,您应该切换到POST
方法:
curl_setopt_array(
$ch, array(
CURLOPT_URL => 'http://e4allds/',
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $postData,
CURLOPT_RETURNTRANSFER => true
));
curl_setopt_array(
$ch, array(
CURLOPT_URL => 'http://e4allds/?' . http_build_query($postData,null,'&'),
CURLOPT_RETURNTRANSFER => true
));
或者,如果希望继续使用GET
方法,请将所有参数放入查询字符串中:
curl_setopt_array(
$ch, array(
CURLOPT_URL => 'http://e4allds/',
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $postData,
CURLOPT_RETURNTRANSFER => true
));
curl_setopt_array(
$ch, array(
CURLOPT_URL => 'http://e4allds/?' . http_build_query($postData,null,'&'),
CURLOPT_RETURNTRANSFER => true
));