从表单发布和从服务器发布之间有什么区别? [英] What's the difference between posting from a form and posting from a server?
问题描述
例如,在php服务器上,我从$ _POST捕获了所有发布的变量
On a php-server I capture all posted variables from $_POST, forexample
var_dump($_POST);
如果我使用html表单将其发布到服务器,则此方法很好.
This works fine if I use a html-form to post to the server.
我尝试使用nodejs发布到服务器并请求验证:
I try to post to the server using nodejs and requestify:
requestify.post('http://localhost/rest/1/comment/create', {hello: 'world'})
.then(function(response) {
console.log(response.getBody());
})
这不会被php服务器捕获,并且var_dump($ _ POST)输出一个空数组.
This will not be captured by the php-server and var_dump($_POST) outputs an empty array.
推荐答案
您可以使用 json_decode(file_get_contents("php://input"),true);
片段从PHP读取json请求. php://input
是PHP的STDIN,原始请求可用.详细信息也可以在文档中找到.
You can use json_decode(file_get_contents("php://input"), true);
snippet to read json request from PHP. php://input
is PHP's STDIN where raw request is available. Details also available in docs.
这篇关于从表单发布和从服务器发布之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!