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.

图片转代码服务由CSDN问答提供 功能建议

有一点问题。 我有一些任务,必须在客户服务器系统中处理一些数据。 客户端 我可以在JS上创建不同的http请求。 例如:</ p>

  $ http.post(url,DataObj); 
 $ http.get(url,DataObj);  
 $ http.insert(url,DataObj); 
 $ http.deletet(url,DataObj); 
 $ http.update(url,DataObj); 
 </ code> </ pre> 
 
  

在NodeJS的服务器端,我可以识别请求类型,获取请求数据并执行一些服务器逻辑,之后我可以发回一些ansver或数据对象。 Node JS示例:</ p>

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

问题是我无法理解客户端是怎样的 PHP必须识别请求的类型(发布,更新,实际),获取请求数据以处理它并发送结果结果数据。 n我可以在一个脚本中完成所有这些操作,或者必须使用以下数据为每个操作制作一些 scripts:</ p>

  getData.php 
insertData.php 
updateData  .php 
deleteData.php 
 </ code> </ pre> 
 
 

如果有人有类似的任务,请分享我能理解的代码示例,或参考示例。 非常感谢你。</ p> </ div>

1条回答 默认 最新

相关推荐 更多相似问题