PHP swirl request for strange parameters

I try to automate the registration for classes (because I forget to do this all the time) When I register manually, it uses this URL for classes on a specific day:

https://URL.com/public/tickets.php?PRESET%5BTickets%5D%5Bname%5D%5B%5D=&PRESET%5BTickets%5D%5Bday%5D%5B%5D=2018-03-04

which decodes in

https://URL.com/public/tickets.php?PRESET[Tickets][name][]=&PRESET[Tickets][day][]=2018-03-04

But it’s most difficult for them to translate this into a curl request. I (among other things) tried

$data = array("PRESET" => array("Tickets" => array("name"=>array(""), "day"=> array("2018-03-02"))));

and

$data = array('PRESET[Tickets][naam][]=', 'PRESET[Tickets][naam][]=');

But I always get a page where no day has been selected. Sometimes a page has a php error about a parameter that is expected to be an array.

this is my curl request

curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_URL, $targetSite);
curl_setopt($curl, CURLOPT_COOKIEFILE, $this->cookie);
curl_setopt($curl, CURLOPT_COOKIEJAR, $this->cookie);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);

Can someone tell me how to send parameters correctly using a curl request? Thank you

+4
source share
1 answer

CURLOPT_POSTFIELDS, , URL- . , CURLOPT_POSTFIELDS , curl multipart/form-data -format, urlencoded ( multipart/form-data). POST- http_build_query URL-,

curl_setopt ( $ch, CURLOPT_URL, "https://URL.com/public/tickets.php?" . http_build_query ( array (
        'PRESET' => array (
                'Tickets' => array (
                        'name' => array (
                                0 => '' 
                        ),
                        'day' => array (
                                0 => '2018-03-04' 
                        ) 
                ) 
        ) 
) ) );

protip, parse_str() URL- php-, , , var_export PHP- , , , , http_build_query url, .

+3

Source: https://habr.com/ru/post/1694422/


All Articles