0

I try to make a request from my php code to another remote server which has Riak DB running. I need to make a map-reduce request so I have to do it with POST http.

Riak documentation says (for e.g.)

curl -XPOST http://`localhost`:8091/mapred \
-H 'Content-Type: application/json' \
-d '{
"inputs":"training",
"query":[{"map":{"language":"javascript",
"source":"function(riakObject) {
var m = riakObject.values[0].data.match(/pizza/g);
return [[riakObject.key, (m ? m.length : 0 )]];
}"}}]}'

How to do the same with PHP?

kikulikov
  • 2,512
  • 4
  • 29
  • 45

1 Answers1

2

http://php.net/manual/en/book.curl.php

You can use the PHP cUrl library for this. Be sure to enable it in the PHP modules.

Edit:

the --data flag tells cUrl to use POST, this is the PHP variant

curl_setopt($ch, CURLOPT_POST,           TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS,     $body)

Where the body variable can be the data, for example JSon.

Simplect
  • 286
  • 1
  • 4