Как добавить значения REQUEST к методу HTTP POST с помощью multipart для загрузки файла на PHP-сервер в Android?

Итак, я пытаюсь загрузить файл на свой PHP-сервер. Я нашел некоторый код онлайн, который работает, но мне также нужно включить значения для таких вещей, как аутентификация пользователя, и где на сервере файл должен быть загружен. Я относительно новичок в HTTP-связи, и код, который я нашел ниже, использует термины / код, о которых я никогда не слышал, прежде всего, Content-Type и Content-Disposition multipart/form-data . Поэтому, если кто-то может рассказать мне, как включать нужные мне ценности, предоставить другой метод целиком или просто объяснить эти три термина для меня, как будто мне пять, я бы очень признателен. Вот мой код:

 public static void upload(String path, String section, Context c){ Log.i("path", path); HttpURLConnection conn = null; DataOutputStream dos = null; DataInputStream inStream = null; String lineEnd = "\r\n"; String twoHyphens = "--"; String boundary = "*****"; int bytesRead, bytesAvailable, bufferSize; byte[] buffer; int maxBufferSize = 1 * 1024 * 1024; String responseFromServer = ""; String urlString = c.getString(R.string.server) + "upload.php"; try { // ------------------ CLIENT REQUEST FileInputStream fileInputStream = new FileInputStream(new File( path)); // open a URL connection to the Servlet URL url = new URL(urlString); // Open a HTTP connection to the URL conn = (HttpURLConnection) url.openConnection(); // Allow Inputs conn.setDoInput(true); // Allow Outputs conn.setDoOutput(true); // Don't use a cached copy. conn.setUseCaches(false); // Use a post method. conn.setRequestMethod("POST"); conn.setRequestProperty("Connection", "Keep-Alive"); conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary); dos = new DataOutputStream(conn.getOutputStream()); dos.writeBytes(twoHyphens + boundary + lineEnd); dos.writeBytes("Content-Disposition: form-data; name=\"uploadedfile\";filename=\"" + path + "\"" + lineEnd); dos.writeBytes(lineEnd); // create a buffer of maximum size bytesAvailable = fileInputStream.available(); bufferSize = Math.min(bytesAvailable, maxBufferSize); buffer = new byte[bufferSize]; // read file and write it into form... bytesRead = fileInputStream.read(buffer, 0, bufferSize); while (bytesRead > 0) { dos.write(buffer, 0, bufferSize); bytesAvailable = fileInputStream.available(); bufferSize = Math.min(bytesAvailable, maxBufferSize); bytesRead = fileInputStream.read(buffer, 0, bufferSize); } // send multipart form data necesssary after file data... dos.writeBytes(lineEnd); dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd); // close streams Log.e("Debug", "File is written"); fileInputStream.close(); dos.flush(); dos.close(); } catch (MalformedURLException ex) { Log.e("Debug", "error: " + ex.getMessage(), ex); } catch (IOException ioe) { Log.e("Debug", "error: " + ioe.getMessage(), ioe); } // ------------------ read the SERVER RESPONSE try { inStream = new DataInputStream(conn.getInputStream()); String str; while ((str = inStream.readLine()) != null) { Log.e("Debug", "Server Response " + str); } inStream.close(); } catch (IOException ioex) { Log.e("Debug", "error: " + ioex.getMessage(), ioex); } } 

** Редактирование: просто чтобы быть немного более ясным, мне хотелось бы, чтобы в моем PHP-скрипте я мог получить доступ к таким значениям, как $ _REQUEST ['path'] (который мог бы = '/ documents /' или что-то еще), а также фактический файл с $ _FILES ['uploadedfile']

 String urlToSendRequest = "https://example.net"; String targetDomain = "example.net"; DefaultHttpClient httpClient = new DefaultHttpClient(); HttpHost targetHost = new HttpHost(targetDomain, 80, "http"); HttpPost httpPost = new HttpPost(urlToSendRequest); // Make sure the server knows what kind of a response we will accept // httpPost.addHeader("Accept", "text/xml"); // Also be sure to tell the server what kind of content we are sending httpPost.addHeader("Content-Type", "application/xml"); StringEntity entity = new StringEntity("<input>test</input>", "UTF-8"); entity.setContentType("application/xml"); httpPost.setEntity(entity); HttpResponse response = httpClient.execute(httpPost, context); Reader r = new InputStreamReader(response.getEntity().getContent());