user3388006
user3388006

Reputation: 1

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

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?

Upvotes: 0

Views: 3297

Answers (2)

poncha
poncha

Reputation: 7856

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
    ));

Upvotes: 0

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
));

Upvotes: 2

Related Questions