Hi everyone, I'm trying to create a login function in my new App.
I wrote a php file in my server to be an interface between my App and MySQL.
JAVA code
1. I'd try the php file in a web browser and it operates normally, I'm sure the problem came from the JAVA code.
2. I'd try to use the response.getStatusLine().getStatusCode() method to check the HTTP status code, but it doesn't return any number.
Please help !
I wrote a php file in my server to be an interface between my App and MySQL.
JAVA code
PHP code // To improve readability, I deleted irrelevant codes and simplify the remaining, aims to show what I'm going to do.private void connectPHP(){
try {
HttpClient client = new DefaultHttpClient();
HttpPost request = new HttpPost("www.abc.com/login.php"); // I hide the actual URL for security reason.
ArrayList<NameValuePair> parameters = new ArrayList<NameValuePair>();
parameters.add(new BasicNameValuePair("username", "user"));
parameters.add(new BasicNameValuePair("password", "pw"));
request.setEntity(new UrlEncodedFormEntity(parameters, "UTF_8"));
HttpResponse response = client.execute(request);
String responseMessage = response.getEntity().toString();
} catch (Exception e) {}
}
I expect responseMessage will equal to "Success", but as result it returns a NULL value.<?php
if ($_POST['username'] == 'user' && $_POST['password'] == 'pw')
echo 'Success';
else
echo 'Failed';
?>
1. I'd try the php file in a web browser and it operates normally, I'm sure the problem came from the JAVA code.
2. I'd try to use the response.getStatusLine().getStatusCode() method to check the HTTP status code, but it doesn't return any number.
Please help !

!