I have an Android app that sends a http post to a remote server:
protected Void doInBackground(Void... params) {
// Get the message from the intent
Intent intent = getIntent();
String message = intent.getStringExtra(MapsActivity.EXTRA_MESSAGE);
double longitude = intent.getDoubleExtra(MapsActivity.EXTRA_LONGITUDE, 0.0);
double latitude = intent.getDoubleExtra(MapsActivity.EXTRA_LATITUDE, 0.0);
Log.d("doInBackground", message);
Log.d("doInBackground", String.valueOf(longitude));
Log.d("doInBackground", String.valueOf(latitude));
URL url = null;
HttpURLConnection client = null;
try {
// Establish http connection
url = new URL("http://******.com/");
client = (HttpURLConnection) url.openConnection();
client.setDoOutput(true);
client.setDoInput(true);
client.setRequestMethod("POST");
client.connect();
OutputStreamWriter writer = new OutputStreamWriter(client.getOutputStream());
String output;
output = URLEncoder.encode("message", "UTF-8")
+ "=" + URLEncoder.encode(message, "UTF-8");
output += "&" + URLEncoder.encode("longitude", "UTF-8") + "="
+ URLEncoder.encode(String.valueOf(longitude), "UTF-8");
output += "&" + URLEncoder.encode("latitude", "UTF-8") + "="
+ URLEncoder.encode(String.valueOf(latitude), "UTF-8");
Log.d("doInBackground(output)", output);
Log.d("doInBackground(code)", String.valueOf(client.getResponseCode())); // Return 200
writer.write(output);
writer.flush();
writer.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
client.disconnect();
}
return null;
}
In the server, I have:
<?php
$m = urldecode($_POST['message']);
$long = urldecode($_POST['longitude']);
$lat = urldecode($_POST['latitude']);
print " ==== POST DATA =====
Message : $m
Longitude : $long
Latitude : $lat";
?>
client.getResponseCode() returns 200, I think that means my connection was successful? But the website still shows nothing. What might cause the problem? I got
E/GMPM: getGoogleAppId failed with status: 10
E/GMPM: Uploading is not possible. App measurement disabled
might this be the problem?