0

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'.

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?

2 Answers 2

2

You need to enable the cURL POST parameter to 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
));
Sign up to request clarification or add additional context in comments.

Comments

0

According to manual, CURLOPT_POSTFIELDS option is The full data to post in a HTTP "POST" operation.

So, either you should switch to POST method:

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:

curl_setopt_array(
  $ch, array( 
    CURLOPT_URL => 'http://e4allds/?' . http_build_query($postData,null,'&'),
    CURLOPT_RETURNTRANSFER => true
    ));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.