Encode you file : base64
byte[] bt=
// Conversion B64
String result=DatatypeConverter.printBase64Binary(bt);
put it in a doPost as parameter
use java.net.URLConnection:
String urlParameters = "my_file=my_long_file_inbase64_here";
byte[] postData = urlParameters.getBytes( StandardCharsets.UTF_8 );
int postDataLength = postData.length;
String request = "http://otherserver.com/myservlet";
URL url = new URL( request );
HttpURLConnection conn= (HttpURLConnection) url.openConnection();
conn.setDoOutput( true );
conn.setInstanceFollowRedirects( false );
conn.setRequestMethod( "POST" );
conn.setRequestProperty( "Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty( "charset", "utf-8");
conn.setRequestProperty( "Content-Length", Integer.toString( postDataLength ));
conn.setUseCaches( false );
try( DataOutputStream wr = new DataOutputStream( conn.getOutputStream())) {
wr.write( postData );
}
from this: Java - sending HTTP parameters via POST method easily
just decode it at the other side
byte [] byteArray=DatatypeConverter.parseBase64Binary(result);
You can also use multipart post (no need)
You get your data in doPost: doGet and doPost in Servlets
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
mydata_serialized = req.getParameter("my_file");