PHP | 在AJAX中使用Curl POST变量

How to replicate this data post by ajax with curl?

  ...
  data: {
    search: JSON.stringify({
    daterange : "custom", 
    daterangecustom  : {
        start   : "2013-03-01T23:59:59",
        end     : "2018-03-01T23:59:59"
      }
    }),
    limit: 50
  },
  ...

I dont need the whole code for curl, but only $params value:

curl_setopt($curl, CURLOPT_POSTFIELDS, $params);

I`ve been trying to make this work for a while, with no success. Thanks a lot to anyone with a solution here!!

Without knowing a little more, I think this is what you are looking for:

$data = array(
    'search' => array(
        'daterange' => 'custom',
        'daterangecustom' => array(
            'start' => '2013-03-01T23:59:59',
            'end'   => '2018-03-01T23:59:59',
        ),
    ),
    'limit' => 50,
);

$headers = array(
    'Content-type: application/json',
);

curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

The request will look like this:

POST /url HTTP/1.1
Host: host
Accept: */*
Content-type: application/json
Content-Length: 122

{"search":{"daterange":"custom","daterangecustom":{"start":"2013-03-01T23:59:59","end":"2018-03-01T23:59:59"}},"limit":50}