Reputation: 17
I'm trying to implement a simple login system in my application. The C# application would send a POST request with user id and password to the PHP script. Then the PHP script would check if the user id exists, and if the password is correct. If yes, it would return some data(time left, unique id). I'm not sure how to return the data to my application though, what would be the best way in your opinion?
Thanks.
Upvotes: 0
Views: 438
Reputation: 449415
Just echoing it in the response body as usual would be the most obvious option. If it's more complex data, you could use a standard like json_encode()
that you can parse in C#.
Example:
$data["time_left"] = 12023932103129;
$data["unique_id"] = 203032924420;
echo json_encode($data); // will output a JSON string that you can decode
// in C#.
Additionally, you could consider using status codes for error handling, for example:
if ($error)
{
header("HTTP/1.1 500 Internal Server Error");
echo "Details of the error in here";
}
Upvotes: 1
Reputation: 26922
echo it in the response as an xml-document, so let php build a valid xml document. C# is particularly good in parsing xml.
string xml = /* get your xml document from php */
var xDocument = XDocument.Parse(xml);
http://msdn.microsoft.com/en-us/library/bb345532.aspx
Upvotes: 1