[英]request URL with parameters in curl php
I want to request for a certain web page content for particular option selected from drop down list. 我想要从下拉列表中选择特定选项的特定网页内容。
In my example, I want content from web page where Community and Level are two drop down lists. 在我的示例中,我想要来自网页的内容,其中社区和级别是两个下拉列表。 and I want web page for option
Community='SoftwareFactory/Cloude'
and Level='V6R2015x'
. 我想要选项
Community='SoftwareFactory/Cloude'
和Level='V6R2015x'
。
My code is 我的代码是
<?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;
But its giving result for default selection. 但它给出了默认选择的结果。 Could anyone please help me how can I pass these parameters to the URL?
有谁可以帮助我如何将这些参数传递给URL?
You need to enable the cURL
POST parameter to true
. 您需要将
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
));
According to manual , CURLOPT_POSTFIELDS
option is The full data to post in a HTTP "POST" operation . 根据手册 ,
CURLOPT_POSTFIELDS
选项是在HTTP“POST”操作中发布的完整数据 。
So, either you should switch to POST
method: 所以,要么你应该切换到
POST
方法:
curl_setopt_array(
$ch, array(
CURLOPT_URL => 'http://e4allds/',
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $postData,
CURLOPT_RETURNTRANSFER => true
));
or, put all the parameters in the query-string if you wish to keep using GET
method: 或者,如果您希望继续使用
GET
方法,请将所有参数放在查询字符串中:
curl_setopt_array(
$ch, array(
CURLOPT_URL => 'http://e4allds/?' . http_build_query($postData,null,'&'),
CURLOPT_RETURNTRANSFER => true
));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.