duananyu9231 2013-06-13 13:09
浏览 126
已采纳

php发布请求--data

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?

  • 写回答

1条回答 默认 最新

  • duanke1984 2013-06-13 13:13
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥15 小红薯封设备能解决的来
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答
  • ¥20 在本地部署CHATRWKV时遇到了AttributeError: 'str' object has no attribute 'requires_grad'
  • ¥15 vue+element项目中多tag时,切换Tab时iframe套第三方html页面需要实现不刷新
  • ¥50 深度强化学习解决能源调度问题
  • ¥15 一道计算机组成原理问题