//create http connection with multipart/form-data Content-Type //i.e. simulating "Validate by File Upload" @@ String boundary = "AaB03x", eol = "\r\n", s; HttpURLConnection httpC = (HttpURLConnection)new URL(link).openConnection(); httpC.setDoOutput(true); httpC.setDoInput(true); httpC.setUseCaches(false); httpC.setRequestMethod("POST"); httpC.setRequestProperty("Connection", "Keep-Alive"); httpC.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary); httpC.setRequestProperty("Content-Length", "xxx"); //send the html file to w3c DataOutputStream out = new DataOutputStream(httpC.getOutputStream()); s = "--" + boundary + eol + "Content-Disposition: form-data; name=\"ss\"" + eol @@ + "Content-Type: text/html; charset=ISO-8859-1" + eol + eol + 1 + eol + "--" + boundary + eol @@ + "Content-Disposition: form-data; name=\"uploaded_file\"; filename=\"" // whats the string "uploaded_file" for? + args[0] + "\"" + eol @@ + "Content-Type: text/html; charset=ISO-8859-1" + eol + eol; // <- image/jpeg out.writeBytes(s); BufferedReader in = new BufferedReader(new FileReader(args[0])); for(; (s = in.readLine()) != null; ) out.writeBytes(s + "\n"); in.close(); out.writeBytes( eol + "--" + boundary + "--" + eol); out.flush(); out.close(); //read and print the results from w3c in = new BufferedReader(new InputStreamReader(httpC.getInputStream())); for(; (s = in.readLine()) != null; ) System.out.println(s); in.close();