I am writing an app that will send an id, latitude, and longitude to a server using an HTTP POST. The app will be using user data. Is there a way to determine the size in bytes of the post before I send it?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView tvLatLong = (TextView) findViewById(R.id.tvLatLong);
LocationServices.startUpdates(this, tvLatLong);
Button btnPost = (Button) findViewById(R.id.btnSend);
btnPost.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
id = 1;
latitude = LocationServices.getLatitude();
longitude = LocationServices.getLongitude();
Log.i("USER ID ::", id + "");
Log.i("USER LATITUDE ::", latitude + "");
Log.i("USER LONGITUDE ::", longitude + "");
List<NameValuePair> list = new ArrayList<NameValuePair>();
list.add(new BasicNameValuePair("keyId", id + ""));
list.add(new BasicNameValuePair("latitude", latitude + ""));
list.add(new BasicNameValuePair("longitude", longitude + ""));
post(list);
}
});
}
private void post(List<NameValuePair> list) {
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("http://dmark3.apsu.edu");
try{
post.setEntity(new UrlEncodedFormEntity(list));
HttpResponse response = client.execute(post);
Log.i("HTTP RESPONSE :: ", response.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
Above is the code.