科尔多瓦:无法获取请求参数在服务器端使用$ _ POST值 [英] Cordova: Can not get the request parameters values at server side using $_POST

查看:115
本文介绍了科尔多瓦:无法获取请求参数在服务器端使用$ _ POST值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发我的web应用程序的所有数据驻留在服务器上的一个移动应用程序。在POST请求的数据将在JSON格式响应发送。我做一个职位要求如下:

  $ http.defaults.headers.post ['内容类型'] ='应用/的X WWW的形式urlen $ C $光盘';
$ http.post(BASE_URL +获得/ memberLogin.php,{用户名:用户名,密码:密码,'tempKey':'XHJJUQWERgfrbbbbokaw1222344'} ...

数据在POST请求得到发送,我可以在Firefox浏览器中的萤火虫看到。但在服务器端,当我做的var_dump($ _ POST)的var_dump($ _ REQUEST)我收到空数组。怎么会这样?由于我在服务器上发布的数据,应该使用捕获 $ _ POST ,但没有工作。

相反,如果我以以下格式发送数据:

  $ http.post(BASE_URL +获得/ memberLogin.php用户名=?+使用者名称+&放大器;密码=+密码,{} ...

我在服务器端使用获取的参数值 $ _ REQUEST 。什么是 $问题_ POST ??


解决方案

  

但在服务器端,当我做的var_dump($ _ POST)或后续代码var_dump($ _ REQUEST)我得到空数组。


当你的内容类型设置为应用程序/ x-WWW的形式urlen codeD,角被编码数据作为JSON。

PHP不能解析它(因为它不是应用程序/ x-WWW的形式urlen codeD),所以它没有数据来填充 $ _ POST 室内用。


  

我在服务器端使用$ _REQUEST得到的参数值。什么是$ _ POST问题??


PHP有愚蠢的命名约定。

$ _ GET 不从GET请求包含的所有数据。它包含一个查询字符串数据。

$ _ POST 不从POST请求包含的所有数据。它包含请求主体的数据。

  $ http.post(BASE_URL +GET / memberLogin.php用户名=+使用者名称+&放大器;密码=+密码

...使POST请求,但你把所有的数据在查询字符串(你应该将其通过连接codeURIComponent 第一)。

I am developing mobile application for one of my webapp whose all the data resides on server. On post request data will be sent in response in JSON format. I am doing a post request as follows:

$http.defaults.headers.post['Content-Type'] ='application/x-www-form-urlencoded';
$http.post(base_url+"get/memberLogin.php", {'username':userName, 'password':passWord, 'tempKey':'XHJJUQWERgfrbbbbokaw1222344'}...

the data is getting sent in post request as that of i can see in the firebug of firefox browser. But at server side when i do var_dump($_POST) or var_dump($_REQUEST) i am getting the empty array. How is it so??? As i am posting data on server, it should be captured using $_POST but didnt work

Instead if i send data in following format:

$http.post(base_url+"get/memberLogin.php?username="+userName+"&password="+passWord, {}...

I am getting parameter values at server side using $_REQUEST. What is the problem with $_POST??

解决方案

But at server side when i do var_dump($_POST) or var_dump($_REQUEST) i am getting the empty array.

While you are setting the content-type to application/x-www-form-urlencoded, Angular is encoding the data as JSON.

PHP fails to parse it (because it isn't application/x-www-form-urlencoded) so it has no data to populate $_POST wiht.

I am getting parameter values at server side using $_REQUEST. What is the problem with $_POST??

PHP has stupid naming conventions.

$_GET does not contain all data from a GET request. It contains data from a query string.

$_POST does not contain all data from a POST request. It contains data from the request body.

This:

$http.post(base_url+"get/memberLogin.php?username="+userName+"&password="+passWord

… makes a POST request, but you are putting all the data in the query string (where you should be passing it through encodeURIComponent first).

这篇关于科尔多瓦:无法获取请求参数在服务器端使用$ _ POST值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆