web - 是不是只要app用的是post过来的,php都可以直接获取?

WBOY
Release: 2016-06-06 20:27:59
Original
1215 people have browsed it

对方说自己用的是asihttp,post过来的。

那么我能直接接收到吗?还有如何检测我有没有收到别人post过来的数据或别人有没有发送数据过来?

<code><?php $json=$_POST;
$json=json_decode[$json,true];
$conn=@mysql_connect("localhost:3306","root","")or die ("数据库链接失败");
mysql_select_db("test",$conn);
$sql = mysql_query("insert into table value ($json[0]);");
mysql_close;
?></code>
Copy after login
Copy after login

回复内容:

对方说自己用的是asihttp,post过来的。

那么我能直接接收到吗?还有如何检测我有没有收到别人post过来的数据或别人有没有发送数据过来?

<code><?php $json=$_POST;
$json=json_decode[$json,true];
$conn=@mysql_connect("localhost:3306","root","")or die ("数据库链接失败");
mysql_select_db("test",$conn);
$sql = mysql_query("insert into table value ($json[0]);");
mysql_close;
?></code>
Copy after login
Copy after login

不是,post过来的也需要是key value的键值对才能$_POST读取。
$raw = file_get_contents("php://input","r");

可以接受任何形式的post数据

这个是php语言,只要有人提交post过来,才会执行。所以需要知道别人是不是post过来。
如果你是想知道如何验证是不是你自己的app提交的数据,可以考虑使用签名的方式对传过来的数据验证。

只要网络连接没有问题,那么app端发送post请求的数据都能在php直接获取。只有通过判断接收的数据是否为空来检测是否传数据过来。

首先,对于楼主的代码,我有几个疑问:
$json=json_decode[$json,true]这一行,对数组做json_decode做啥子?
mysql_close这一行,没有括号,应该是mysql_close();

对方只要是用http的post方法post过来的,你就能用POST来接受,你可以尝试用
if(empty($_POST['username'])){
exit('username can not be empty');
}
来做检验。

看nginx日志,http返回状态,都行的

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!