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 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题