I have an android application that uses HTTP POST to send username,password and type of action to PHP .
Now Is it possible to specify the order of parameters in Reading code just as in the Updating code.I just want to add parameter as an arraylist same as in the Updating Code.
This way parameter i can specify which parameter is sent first am I right ??
Reading Code
public Boolean postData2(String a,String b) {
//Temp Read
String read="read";
HttpURLConnection connection;
OutputStreamWriter request = null;
URL url = null;
response = null;
// String ID=read;
String parameters = "username="+a+"&password="+b+"read"+read;
try
{
url = new URL();
connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setRequestMethod("POST");
request = new OutputStreamWriter(connection.getOutputStream());
//request.write(ID);
request.write(parameters);
request.flush();
request.close();
String line = "";
InputStreamReader isr = new InputStreamReader(connection.getInputStream());
BufferedReader reader = new BufferedReader(isr);
StringBuilder sb = new StringBuilder();
while ((line = reader.readLine()) != null)
{
x=reader.readLine();
y=reader.readLine();
z=reader.readLine();
//String x=reader.readLine();
// sb=line.toString();
// sb.append(line + "
");
}
// Response from server after login process will be stored in response variable.
response = x+y+z;
// You can perform UI operations here
isr.close();
reader.close();
//End Temp Read
} catch (Exception e) {
//res.setText(e.toString());
e.printStackTrace();
}
return true;
}
Updating Code
String update="test";
try{
ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
SharedPreferences settings = getSharedPreferences("mySettings", Activity.MODE_PRIVATE);
us = settings.getString("storedWifiUser", "");
ps = settings.getString("storedWifiPass", "");
postParameters.add(new BasicNameValuePair("update", update));
postParameters.add(new BasicNameValuePair("toggle", a));
postParameters.add(new BasicNameValuePair("status", b));
postParameters.add(new BasicNameValuePair("user", us));
postParameters.add(new BasicNameValuePair("password", ps));