I would like upload any data (Username, Description,..) and a photo from my Android-App to my Server (PHP-Script).
By searching for this i found a solution: How to take a photo and send to HTTP POST request with Android?
By click on my send button, the upload-process starts and the php-script works but the $_POST -Vars are empty? Can anybody help me? My request-code:
[...]
case R.id.btnSend:
String strName = tName.getText().toString();
String strEmail = tEmail.getText().toString();
String strDatum = tDatum.getText().toString();
String strBeschreibung = tBeschreibung.getText().toString();
nvPairs = new ArrayList<NameValuePair>(2);
nvPairs.add(new BasicNameValuePair("sender", "AndoidApp"));
nvPairs.add(new BasicNameValuePair("name", strName));
nvPairs.add(new BasicNameValuePair("email", strEmail));
nvPairs.add(new BasicNameValuePair("datum", strDatum));
nvPairs.add(new BasicNameValuePair("beschreibung", strBeschreibung));
nvPairs.add(new BasicNameValuePair("bild", bmpUrl));
new UploadTask().execute();
}
[...]
private class UploadTask extends AsyncTask<Void, Void, List<String>> {
@Override
protected List<String> doInBackground(Void... params) {
String response = "";
try {
response = new MultipartServer().postData(new URL(postUrl), nvPairs);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
On the MultipartServer-Code i changed the line:
if ((avatarName = pair.getName()).equals("avatar")) {
avatarPath = pair.getValue();
}
to this:
if ((avatarName = pair.getName()).equals("bild")) {
avatarPath = pair.getValue();
}
And the Variables "bmpUrl" and "postUrl" are set correctly at an another line in my code.
the $_POST -Vars are empty?. That is php. But you did not show your php script. Please do. What is the return string if postData()?new UploadTask().execute();you're not passing the data. See the documentation for an example and specifically take note thatexecuteis passed variables when called.