I need to be able to get the http header code in android which is going to be generated by a php code.
I am very new to android and not able to grasp the correct way to do it.
Currently the code I have on my signup.java file is able to post some data to the php based webservice and depending on the data sent the webservice echo a json encoded response.
The php code for response when an error occurs is
$response["error"] = true;
$response["message"] = "Username Already taken";
echoRespnse(400,$response);
and the code on success is
$response["error"] = false;
$response["message"] = "Successfuly Registered";
echoRespnse(201,$response);
This will generate a json ecoded response message.
My signup.java file has the following code
public void post() throws UnsupportedEncodingException
{
// Get user defined values
uname = username.getText().toString();
email = mail.getText().toString();
password = pass.getText().toString();
confirmpass = cpass.getText().toString();
phone = phn.getText().toString();
HttpClient httpclient = new DefaultHttpClient();
HttpResponse httpResponse = null;
HttpPost httppost = new HttpPost("http://www.rgbpallete.in/led/api/signup");
if (password.equals(confirmpass)) {
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(4);
nameValuePairs.add(new BasicNameValuePair("uname", uname));
nameValuePairs.add(new BasicNameValuePair("pass", password));
nameValuePairs.add(new BasicNameValuePair("email", email));
nameValuePairs.add(new BasicNameValuePair("phone", phone));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
httpResponse = httpclient.execute(httppost); //http header response??
//Code to check if user was successfully created
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
else
{
Toast.makeText(getBaseContext(), "Password mismatch", Toast.LENGTH_SHORT).show();
//Reset password fields
pass.setText("");
cpass.setText("");
}
}
I want to know if httpResponse
will hold the http header response code being generated by the webservice or will I need to parse the json response message to understand what is being returned by the webserivce.