S
S
Sergey Sova2014-09-16 13:24:45
PHP
Sergey Sova, 2014-09-16 13:24:45

How to send value to php_curl like console -d?

I do. request via console in ElasticSearch:
curl -XPOST ' localhost:9200/events/play/_bulk ' -d '
{"metadata": {}}
{"element": 1}'
How to send what is passed after -d in PHP with using the php_curl extension?

$c = curl_init();
$opts = [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_URL => $address,
CURLOPT_BINARYTRANSFER => true,
CURLOPT_POST => true,
// CURLOPT_POSTFIELDS = [], // ???
];
curl_setopt_array($c, $opts);
$res = curl_exec($c);
curl_close($c);

As a matter of fact it is necessary to transfer string with transfers (\n).
Everything works through the console. In PHP, requests are sent, but there are no changes in Elastica.
No need to suggest using exec and elasticsearch driver
Thank you all in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Philipp, 2014-09-16
@LestaD

Add

curl_setopt($c, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));  
$pf = "{\"metadata\": {}}\n{\"element\": 1}";
curl_setopt($c, CURLOPT_POSTFIELDS, $pf);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question