[英]php post request with --data
I try to make a request from my php code to another remote server which has Riak DB running. 我尝试从我的PHP代码向另一个运行Riak DB的远程服务器发出请求。 I need to make a map-reduce request so I have to do it with POST http.
我需要制作map-reduce请求,所以我必须使用POST http。
Riak documentation says (for eg) Riak文档说(例如)
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? 如何用PHP做同样的事情?
http://php.net/manual/en/book.curl.php http://php.net/manual/en/book.curl.php
You can use the PHP cUrl library for this. 您可以使用PHP cUrl库。 Be sure to enable it in the PHP modules.
一定要在PHP模块中启用它。
Edit: 编辑:
the --data flag tells cUrl to use POST, this is the PHP variant --data标志告诉cUrl使用POST,这是PHP的变体
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body)
Where the body variable can be the data, for example JSon. body变量可以是数据,例如JSon。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.