I have a Login class that will parse an xml sent from an iOS, Android phone. I'm not very good at php and my question is, how do I make my php page wait for a post? or do I just use
我有一个Login类,它将解析从iOS,Android手机发送的xml。我不是很擅长php,我的问题是,如何让我的php页面等待帖子?或者我只是使用
$xml = $_POST['login.xml'];
....
//parse
....
echo $responsexml;
he also suggested
他还建议道
$xml=readfile("php://input");
to read the xml string. I'm much confused about this post business. Any help will be greatly apreaciated!
读取xml字符串。我对这个邮政业务感到很困惑。任何帮助都将大大提升!
1 个解决方案
#1
1
When XML string will be sent via HTTP POST request, e. g. in your case in "login.xml" parameter, so yes, you can get this content by this code:
当XML字符串将通过HTTP POST请求发送时,e。 G。在您的情况下,在“login.xml”参数中,是的,您可以通过以下代码获取此内容:
$xml = $_POST['login.xml'];
// parsing here...
If you do not know in which parameter data will be, you can iterate through array $_POST. But it is unusual. When you are developing an app, at first you should create API in PHP and then you have to give developers of iOS and Android apps some specification, in which format data should be transferred (or, worse, they will give you some specification of in which format they are sending data).
如果您不知道将在哪个参数数据中,您可以遍历数组$ _POST。但这很不寻常。在开发应用程序时,首先应该用PHP创建API,然后你必须为iOS和Android应用程序的开发人员提供一些规范,其中应该传输格式数据(或者更糟糕的是,它们会给你一些规范)他们发送数据的格式)。
By the way. I think the simplest solution for this would be to send a POST request with data parameters "login" and "password", for example. PHP would than run some verification and return some session id. And for all requests of this type, it's better to avoid XML, all data can go via HTTP requests. And then you don't have to parse anything:
顺便一提。我认为最简单的解决方案是发送一个带有数据参数“login”和“password”的POST请求。 PHP会运行一些验证并返回一些会话ID。对于此类型的所有请求,最好避免使用XML,所有数据都可以通过HTTP请求进行。然后你不必解析任何东西:
$login = $_POST['login'];
$password = $_POST['password'];
#1
1
When XML string will be sent via HTTP POST request, e. g. in your case in "login.xml" parameter, so yes, you can get this content by this code:
当XML字符串将通过HTTP POST请求发送时,e。 G。在您的情况下,在“login.xml”参数中,是的,您可以通过以下代码获取此内容:
$xml = $_POST['login.xml'];
// parsing here...
If you do not know in which parameter data will be, you can iterate through array $_POST. But it is unusual. When you are developing an app, at first you should create API in PHP and then you have to give developers of iOS and Android apps some specification, in which format data should be transferred (or, worse, they will give you some specification of in which format they are sending data).
如果您不知道将在哪个参数数据中,您可以遍历数组$ _POST。但这很不寻常。在开发应用程序时,首先应该用PHP创建API,然后你必须为iOS和Android应用程序的开发人员提供一些规范,其中应该传输格式数据(或者更糟糕的是,它们会给你一些规范)他们发送数据的格式)。
By the way. I think the simplest solution for this would be to send a POST request with data parameters "login" and "password", for example. PHP would than run some verification and return some session id. And for all requests of this type, it's better to avoid XML, all data can go via HTTP requests. And then you don't have to parse anything:
顺便一提。我认为最简单的解决方案是发送一个带有数据参数“login”和“password”的POST请求。 PHP会运行一些验证并返回一些会话ID。对于此类型的所有请求,最好避免使用XML,所有数据都可以通过HTTP请求进行。然后你不必解析任何东西:
$login = $_POST['login'];
$password = $_POST['password'];