我想知道是否可以在同一个php页面上进行GET和POST操作,例如
我想发送数据到:
www.example/my.php所以首先GET
www.example/my .php?task = dosomething并POST一些 $ thexml = XML 至
www.example/my.php?task=dosomething,然后就可以像一些代码一样访问这些代码(例如)
//示例代码============================ if($ _ GET [task] ==dosomething){ $ mynewxml = $ _POST [$ thexml]; } // ======================================= ===解决方案
技术上不行,你不能 POST 和 GET 。他们是两种不同的动词,你只能在你的请求中创建一个动词。
然而,你会发现如果你做一个 POST 并在URL中包含参数,例如 yourscript.php?param1 = somevalue& param2 = somevalue ,然后都是 $ _ GET 和 $ _ POST 将填入各自的数据。
这将是明智的阅读HTTP实际工作方式。 www.jmarshall/easy/http/
您应该考虑这是否是您的好系统设计。一个 GET 应该用于不改变服务器数据的请求。一个 POST 可以改变数据。尽管两者都可以实施,但最好遵循这一惯例。否则你永远不知道代理或其他程序将如何处理。
I wanted to know if it is possible to GET and POST on the same php page, for example
I want to send data to:
www.example/my.phpSo first the GET
www.example/my.php?task=dosomethingand POST some $thexml = XML to
www.example/my.php?task=dosomethingand then be able to access both in some code like (example)
// Example Code ============================ if($_GET["task"] == "dosomething"){ $mynewxml = $_POST["$thexml"]; } //==========================================解决方案
Technically no, you cannot POST and GET at the same time. They are two different verbs, and you only get to make one during your request.
However, you will find that if you do a POST and include parameters in the URL, such as yourscript.php?param1=somevalue¶m2=somevalue, then both $_GET and $_POST will be populated with their respective data.
It would be wise to read up on how HTTP actually works. www.jmarshall/easy/http/
You should consider whether or not this is good system design on your part. A GET is supposed to be for requests that don't change data on the server. A POST can change data. Even though both can be implemented to do either, it is best to follow this common practice. You never know what some proxy or other program up the line will do with it otherwise.
更多推荐
我可以POST和GET到相同的PHP页面
发布评论