douhao7677 2015-12-22 11:15
浏览 41
已采纳

在PHP中识别传入的http请求

Have a little problem. I have some task, where must process some data in client server system. On client side i can create diferent http request on JS. For example:

$http.post(url, DataObj);
$http.get(url, DataObj);
$http.insert(url, DataObj);
$http.deletet(url, DataObj);
$http.update(url, DataObj);

On the server side on NodeJS I can identify type of request, get request data and do some server logic, after that i can send back some ansver or data object. Node JS example:

var apiRoutes = express.Router();
apiRoutes.post('route', function(req, res) {
someFunction(req.params.data);
res.send(ResponseDataObj);  }
or
apiRoutes.delete('route', function(req, res) { .... }

The problem is that I can not understand how client-side PHP must identify the type of request (post, update, actually), get request data to process it and send the result result data. Can I do all these manipulations in a single script, or must to make a few scripts for each operation with data like a :

getData.php
insertData.php
updateData.php
deleteData.php

If anyone have a similar task please share code examples that I could understand, or reference to examples. Thank you very much.

  • 写回答

1条回答 默认 最新

  • duanpasi6287 2015-12-22 11:29
    关注

    You can fetch the request method in PHP using $_SERVER['REQUEST_METHOD']. However for a more structured approach (as you're doing with Express) I would advice using a lightweight framework to do the heavy lifting for you. These come to mind:

    Slim Framework

    Lumen

    Silex

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

报告相同问题?

悬赏问题

  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退
  • ¥20 win系统的PYQT程序生成的数据如何放入云服务器阿里云window版?
  • ¥50 invest生境质量模块