简体   繁体   English

在PHP中识别传入的HTTP请求

[英]Identification of incoming http requests in PHP

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. 在客户端,我可以在JS上创建不同的http请求。 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. 在NodeJS的服务器端,我可以识别请求的类型,获取请求数据并执行一些服务器逻辑,然后再发送回ansver或数据对象。 Node JS example: Node JS示例:

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. 问题是我无法理解客户端PHP如何识别请求的类型(发布,更新,实际),获取请求数据以对其进行处理并发送结果结果数据。 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. 非常感谢你。

You can fetch the request method in PHP using $_SERVER['REQUEST_METHOD'] . 您可以使用$_SERVER['REQUEST_METHOD']在PHP中获取请求方法。 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. 但是,对于更结构化的方法(就像使用Express ),我建议使用轻量级框架为您完成繁重的工作。 These come to mind: 这些想到:

Slim Framework 苗条的框架

Lumen 流明

Silex 西莱克斯

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过 forkJoin 和响应识别的并行 http 请求 - Parallel http requests via forkJoin and response identification AngularJS服务器后端处理传入的HTTP请求 - AngularJS Server Backend Handle Incoming HTTP Requests 如何处理环回时传入的HTTP请求 - How to handle incoming http requests on loopback PHP检测传入的jquery $ .get()请求 - PHP detect incoming jquery $.get() requests 注意传入的 HTTP 请求的连接终止 - Node.JS - Watch for connection termination on incoming HTTP requests - Node.JS 是否可以在 Selenium 或 Puppeteer 等自动化软件中读取传入的 HTTP 请求? - Is it possible to read incoming HTTP requests in automation software like Selenium or Puppeteer? 验证传入的请求 - Validate incoming requests 如何让 CloudFlare 工作人员响应来自用户的传入 HTTP 请求? - How can I have a CloudFlare worker respond to incoming HTTP requests from users? 无法连接到网络服务器。 确认Web服务器正在运行,并且传入的HTTP请求没有被防火墙阻止 - Unable to connect to the webserver. Verify that the web server is running and that incoming http requests are not blocked by a firewall 如何在LiveServerTestCase中检查传入的请求? - How to check incoming requests in LiveServerTestCase?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM