Мне нужно загрузить некоторые данные на сервер PHP. Я могу делать сообщения с параметрами:
String url = "http://yourserver";
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
nameValuePairs.add(new BasicNameValuePair("user", "username"));
nameValuePairs.add(new BasicNameValuePair("password", "password"));
try {
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
httpClient.execute(httpPost);
}
Я также могу загрузить файл:
String url = "http://yourserver";
File file = new File(Environment.getExternalStorageDirectory(),
"yourfile");
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
InputStreamEntity reqEntity = new InputStreamEntity(
new FileInputStream(file), -1);
reqEntity.setContentType("binary/octet-stream");
reqEntity.setChunked(true); // Send in multiple parts if needed
httppost.setEntity(reqEntity);
HttpResponse response = httpclient.execute(httppost);
//Do something with response...
}
Но как я могу собрать это вместе? Мне нужно загрузить изображение и параметры в одном сообщении. Благодаря