Ecco un po' di codice per fare una POST HTTP di un file
codice:String bndry = "AaB03x"; String paramName = "file"; String fileName = "filename.txt"; HttpURLConnection httpcon = (HttpURLConnection) ((new URL(url).openConnection())); httpcon.setDoOutput(true); httpcon.setRequestMethod("POST"); httpcon.setRequestProperty("Content-type", "multipart/form-data, boundary=" +bndry); httpcon.connect(); File file = new File(docPath); FileInputStream is = new FileInputStream(file); OutputStream os = httpcon.getOutputStream(); String disptn = "--" +bndry +"\r\ncontent-disposition: form-data; name=\"" +paramName +"\"; filename=\"" +fileName +"\"\r\nContent-Type: text/plain\r\n\r\n"; os.write(disptn.getBytes()); byte[] buffer = new byte[4096]; int bytes_read; while((bytes_read = is.read(buffer)) != -1) { os.write(buffer, 0, bytes_read); } String boundar = "\r\n--" +bndry +"--"; os.write(boundar.getBytes()); os.flush(); os.close(); is.close();

 
			
			 
			 
					
					
					
						 Rispondi quotando
  Rispondi quotando