You need to send a POST request containing several parameters and a file.
String sendfile (String filename, String filepath) throws IOException { String boundary = Long.toHexString(System.currentTimeMillis()); String charset = "UTF-8"; URL url = new URL("..."); File file = new File(filepath); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("POST"); con.setUseCaches(false); con.setDoOutput(true); con.setDoInput(true); con.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary); OutputStream os = con.getOutputStream(); PrintWriter writer = new PrintWriter(new OutputStreamWriter(os, charset), true); writer.println("--" + boundary); writer.println("Content-Disposition: form-data; name=\"key\""); writer.println(); writer.println(key); writer.println("--" + boundary); writer.println("Content-Disposition: form-data; name=\"client_id\""); writer.println(); writer.println(client_id); writer.println("--" + boundary); writer.println("Content-Disposition: form-data; name=\"direction_id\""); writer.println(); writer.println(direction_id); writer.println("--" + boundary); writer.println("Content-Disposition: form-data; name=\"client_files\"; filename=\"" + filename + "\""); writer.println("Content-Type: image/jpg"); writer.println(); BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file))); for (String line; (line = reader.readLine()) != null; ) writer.println(line); writer.println("--" + boundary + "--"); os.flush(); os.close(); BufferedReader in = new BufferedReader( new InputStreamReader( con.getInputStream())); return in.readLine(); } The problem is somewhere in the last block, because the server sees the parameters, but it responds that the file was not found. I tried to comment out the block of sending one parameter, but an authorization error came.
Error code does not issue.