[英]request URL with parameters in curl php
我想要从下拉列表中选择特定选项的特定网页内容。
在我的示例中,我想要来自网页的内容,其中社区和级别是两个下拉列表。 我想要选项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;
但它给出了默认选择的结果。 有谁可以帮助我如何将这些参数传递给URL?
您需要将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
));
根据手册 , CURLOPT_POSTFIELDS
选项是在HTTP“POST”操作中发布的完整数据 。
所以,要么你应该切换到POST
方法:
curl_setopt_array(
$ch, array(
CURLOPT_URL => 'http://e4allds/',
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $postData,
CURLOPT_RETURNTRANSFER => true
));
或者,如果您希望继续使用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.